本文整理汇总了Java中com.googlecode.lanterna.TerminalSize类的典型用法代码示例。如果您正苦于以下问题:Java TerminalSize类的具体用法?Java TerminalSize怎么用?Java TerminalSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TerminalSize类属于com.googlecode.lanterna包,在下文中一共展示了TerminalSize类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPreferredSize
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
@Override
public TerminalSize getPreferredSize(List<Component> components) {
TerminalSize preferredSize = TerminalSize.ZERO;
if(components.isEmpty()) {
return preferredSize.withRelative(
leftMarginSize + rightMarginSize,
topMarginSize + bottomMarginSize);
}
Component[][] table = buildTable(components);
table = eliminateUnusedRowsAndColumns(table);
//Figure out each column first, this can be done independently of the row heights
int preferredWidth = 0;
int preferredHeight = 0;
for(int width: getPreferredColumnWidths(table)) {
preferredWidth += width;
}
for(int height: getPreferredRowHeights(table)) {
preferredHeight += height;
}
preferredSize = preferredSize.withRelative(preferredWidth, preferredHeight);
preferredSize = preferredSize.withRelativeColumns(leftMarginSize + rightMarginSize + (table[0].length - 1) * horizontalSpacing);
preferredSize = preferredSize.withRelativeRows(topMarginSize + bottomMarginSize + (table.length - 1) * verticalSpacing);
return preferredSize;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:27,代码来源:GridLayout.java
示例2: shrinkWidthToFitArea
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
private int shrinkWidthToFitArea(TerminalSize area, int[] columnWidths) {
int totalWidth = 0;
for(int width: columnWidths) {
totalWidth += width;
}
if(totalWidth > area.getColumns()) {
int columnOffset = 0;
do {
if(columnWidths[columnOffset] > 0) {
columnWidths[columnOffset]--;
totalWidth--;
}
if(++columnOffset == numberOfColumns) {
columnOffset = 0;
}
}
while(totalWidth > area.getColumns());
}
return totalWidth;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:21,代码来源:GridLayout.java
示例3: onAdded
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
@Override
public void onAdded(WindowBasedTextGUI textGUI, Window window, List<Window> allWindows) {
WindowDecorationRenderer decorationRenderer = getWindowDecorationRenderer(window);
TerminalSize expectedDecoratedSize = decorationRenderer.getDecoratedSize(window, window.getPreferredSize());
window.setDecoratedSize(expectedDecoratedSize);
if(allWindows.isEmpty()) {
window.setPosition(TerminalPosition.OFFSET_1x1);
}
else if(window.getHints().contains(Window.Hint.CENTERED)) {
int left = (lastKnownScreenSize.getColumns() - expectedDecoratedSize.getColumns()) / 2;
int top = (lastKnownScreenSize.getRows() - expectedDecoratedSize.getRows()) / 2;
window.setPosition(new TerminalPosition(left, top));
}
else {
TerminalPosition nextPosition = allWindows.get(allWindows.size() - 1).getPosition().withRelative(2, 1);
if(nextPosition.getColumn() + expectedDecoratedSize.getColumns() > lastKnownScreenSize.getColumns() ||
nextPosition.getRow() + expectedDecoratedSize.getRows() > lastKnownScreenSize.getRows()) {
nextPosition = TerminalPosition.OFFSET_1x1;
}
window.setPosition(nextPosition);
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:25,代码来源:DefaultWindowManager.java
示例4: main
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final String string = "Hello!";
Random random = new Random();
Terminal terminal = new TestTerminalFactory(args).createTerminal();
terminal.enterPrivateMode();
terminal.clearScreen();
TerminalSize size = terminal.getTerminalSize();
while(true) {
if(terminal.pollInput() != null) {
terminal.exitPrivateMode();
return;
}
terminal.setForegroundColor(new TextColor.RGB(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
terminal.setBackgroundColor(new TextColor.RGB(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
terminal.setCursorPosition(random.nextInt(size.getColumns() - string.length()), random.nextInt(size.getRows()));
printString(terminal, string);
try {
Thread.sleep(200);
}
catch(InterruptedException e) {
}
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:27,代码来源:Terminal24bitColorTest.java
示例5: onResetGrid
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
private void onResetGrid(WindowBasedTextGUI textGUI, Panel gridPanel) {
BigInteger columns = TextInputDialog.showNumberDialog(textGUI, "Reset Grid", "Reset grid to how many columns?", "4");
if(columns == null) {
return;
}
BigInteger prepopulate = TextInputDialog.showNumberDialog(
textGUI,
"Reset Grid",
"Pre-populate grid with how many dummy components?",
columns.toString());
gridPanel.removeAllComponents();
gridPanel.setLayoutManager(newGridLayout(columns.intValue()));
for(int i = 0; i < prepopulate.intValue(); i++) {
gridPanel.addComponent(new EmptySpace(getRandomColor(), new TerminalSize(4, 1)));
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:17,代码来源:DynamicGridLayoutTest.java
示例6: add
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
public void add(Interactable interactable) {
TerminalPosition topLeft = interactable.toBasePane(TerminalPosition.TOP_LEFT_CORNER);
TerminalSize size = interactable.getSize();
interactables.add(interactable);
int index = interactables.size() - 1;
for(int y = topLeft.getRow(); y < topLeft.getRow() + size.getRows(); y++) {
for(int x = topLeft.getColumn(); x < topLeft.getColumn() + size.getColumns(); x++) {
//Make sure it's not outside the map
if(y >= 0 && y < lookupMap.length &&
x >= 0 && x < lookupMap[y].length) {
lookupMap[y][x] = index;
}
}
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:17,代码来源:InteractableLookupMap.java
示例7: main
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final Terminal rawTerminal = new TestTerminalFactory(args).createTerminal();
rawTerminal.enterPrivateMode();
rawTerminal.clearScreen();
rawTerminal.setCursorPosition(5, 5);
printString(rawTerminal, "Waiting for initial size...");
rawTerminal.flush();
TerminalSize initialSize = rawTerminal.getTerminalSize();
rawTerminal.clearScreen();
rawTerminal.setCursorPosition(5, 5);
printString(rawTerminal, "Initial size: ");
rawTerminal.enableSGR(SGR.BOLD);
printString(rawTerminal, initialSize.toString());
rawTerminal.resetColorAndSGR();
rawTerminal.flush();
try {
Thread.sleep(5000);
}
catch(InterruptedException e) {}
rawTerminal.exitPrivateMode();
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:25,代码来源:InitialSizeTest.java
示例8: BasicTextImage
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
/**
* Creates a new BasicTextImage by copying a region of a two-dimensional array of TextCharacter:s. If the area to be
* copied to larger than the source array, a filler character is used.
* @param size Size to create the new BasicTextImage as (and size to copy from the array)
* @param toCopy Array to copy initial data from
* @param initialContent Filler character to use if the source array is smaller than the requested size
*/
private BasicTextImage(TerminalSize size, TextCharacter[][] toCopy, TextCharacter initialContent) {
if(size == null || toCopy == null || initialContent == null) {
throw new IllegalArgumentException("Cannot create BasicTextImage with null " +
(size == null ? "size" : (toCopy == null ? "toCopy" : "filler")));
}
this.size = size;
int rows = size.getRows();
int columns = size.getColumns();
buffer = new TextCharacter[rows][];
for(int y = 0; y < rows; y++) {
buffer[y] = new TextCharacter[columns];
for(int x = 0; x < columns; x++) {
if(y < toCopy.length && x < toCopy[y].length) {
buffer[y][x] = toCopy[y][x];
}
else {
buffer[y][x] = initialContent;
}
}
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:30,代码来源:BasicTextImage.java
示例9: AboutWindow
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public AboutWindow(TerminalSize terminalSize) {
super("About");
Panel p = new Panel(new BorderLayout());
p.addComponent(new Label(ABOUT +
(terminalSize.getColumns() >= 96 ? DIAGRAM :
"[Full diagram included but your terminal should\n" +
" be at least 96 characters wide to show it]")),
BorderLayout.Location.TOP);
p.addComponent(new Button("Close", this::close), BorderLayout.Location.BOTTOM);
setComponent(p);
setHints(Arrays.asList(Window.Hint.CENTERED, Window.Hint.EXPANDED));
}
开发者ID:PumpkinDB,项目名称:pumpkindb-java,代码行数:13,代码来源:AboutWindow.java
示例10: doMenu
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public int doMenu() throws IOException {
BasicWindow window = new BasicWindow();
Panel panel = new Panel();
ActionListBox actionListBox = new ActionListBox(new TerminalSize(50, 4));
Label lblGreet = new Label(mainGreet);
/*actionListBox.addItem(lang.getString("login"), () -> {
selection = 1;
window.close();
});*/
actionListBox.addItem(lang.getString("discussionList"), () -> {
selection = 2;
window.close();
});
actionListBox.addItem(lang.getString("exit"), () -> {
selection = 0;
window.close();
});
panel.addComponent(lblGreet);
panel.addComponent(actionListBox);
window.setComponent(panel);
window.setTitle(lang.getString("mainMenu"));
window.setHints(Arrays.asList(Window.Hint.CENTERED));
this.gui.addWindowAndWait(window);
return this.selection;
}
开发者ID:cnVintage,项目名称:cnVintage-Telnet,代码行数:33,代码来源:FrontEnd.java
示例11: doLogin
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public boolean doLogin(String[] cred) throws IOException
{
BasicWindow window = new BasicWindow();
System.out.println("Creating a new window");
Panel panel = new Panel();
panel.setLayoutManager(new GridLayout(2));
TextBox txtPass = new TextBox();
txtPass.setMask('*');
panel.addComponent(new EmptySpace(new TerminalSize(0,1)));
panel.addComponent(new EmptySpace(new TerminalSize(0,1)));
panel.addComponent(new Label(lang.getString("welcomeBack")));
panel.addComponent(new Label(cred[0]));
panel.addComponent(new EmptySpace(new TerminalSize(0,1)));
panel.addComponent(new EmptySpace(new TerminalSize(0,1)));
panel.addComponent(new Label(lang.getString("token")));
panel.addComponent(txtPass);
panel.addComponent(new EmptySpace(new TerminalSize(0,1)));
panel.addComponent(new EmptySpace(new TerminalSize(0,1)));
panel.addComponent(new EmptySpace(new TerminalSize(0,0)));
panel.addComponent(new Button(lang.getString("loginButton"), window::close));
window.setComponent(panel);
window.setTitle(lang.getString("welcome"));
window.setHints(Arrays.asList(Window.Hint.CENTERED));
this.gui.addWindowAndWait(window);
return (cred[1].equals(txtPass.getText()));
}
开发者ID:cnVintage,项目名称:cnVintage-Telnet,代码行数:38,代码来源:FrontEnd.java
示例12: AbstractBasePane
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
protected AbstractBasePane() {
this.contentHolder = new ContentHolder();
this.interactableLookupMap = new InteractableLookupMap(new TerminalSize(80, 25));
this.invalid = false;
this.strictFocusChange = false;
this.enableDirectionBasedMovements = true;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:8,代码来源:AbstractBasePane.java
示例13: grabExtraHorizontalSpace
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
private int grabExtraHorizontalSpace(TerminalSize area, int[] columnWidths, Set<Integer> expandableColumns, int totalWidth) {
for(int columnIndex: expandableColumns) {
columnWidths[columnIndex]++;
totalWidth++;
if(area.getColumns() == totalWidth) {
break;
}
}
return totalWidth;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:11,代码来源:GridLayout.java
示例14: grabExtraVerticalSpace
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
private int grabExtraVerticalSpace(TerminalSize area, int[] rowHeights, Set<Integer> expandableRows, int totalHeight) {
for(int rowIndex: expandableRows) {
rowHeights[rowIndex]++;
totalHeight++;
if(area.getColumns() == totalHeight) {
break;
}
}
return totalHeight;
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:11,代码来源:GridLayout.java
示例15: getPreferredSize
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
@Override
public TerminalSize getPreferredSize(List<Component> components) {
if(direction == Direction.VERTICAL) {
return getPreferredSizeVertically(components);
}
else {
return getPreferredSizeHorizontally(components);
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:10,代码来源:LinearLayout.java
示例16: onResized
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
/**
* Call this method when the terminal has been resized or the initial size of the terminal has been discovered. It
* will trigger all resize listeners, but only if the size has changed from before.
*
* @param columns Number of columns in the new size
* @param rows Number of rows in the new size
*/
protected synchronized void onResized(int columns, int rows) {
TerminalSize newSize = new TerminalSize(columns, rows);
if (lastKnownSize == null || !lastKnownSize.equals(newSize)) {
lastKnownSize = newSize;
for (ResizeListener resizeListener : resizeListeners) {
resizeListener.onResized(this, lastKnownSize);
}
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:17,代码来源:AbstractTerminal.java
示例17: getTerminalSize
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
@Override
public TerminalSize getTerminalSize() throws IOException {
saveCursorPosition();
setCursorPosition(5000, 5000);
reportPosition();
restoreCursorPosition();
return waitForTerminalSizeReport();
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:9,代码来源:ANSITerminal.java
示例18: getPreferredSize
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
@Override
public TerminalSize getPreferredSize(Border component) {
StandardBorder border = (StandardBorder)component;
Component wrappedComponent = border.getComponent();
TerminalSize preferredSize;
if (wrappedComponent == null) {
preferredSize = TerminalSize.ZERO;
} else {
preferredSize = wrappedComponent.getPreferredSize();
}
preferredSize = preferredSize.withRelativeColumns(2).withRelativeRows(2);
String borderTitle = border.getTitle();
return preferredSize.max(new TerminalSize((borderTitle.isEmpty() ? 2 : borderTitle.length() + 4), 2));
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:15,代码来源:Borders.java
示例19: AbstractComponent
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public AbstractComponent() {
size = TerminalSize.ZERO;
position = TerminalPosition.TOP_LEFT_CORNER;
explicitPreferredSize = null;
layoutData = null;
invalid = true;
parent = null;
renderer = null; //Will be set on the first call to getRenderer()
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:10,代码来源:AbstractComponent.java
示例20: main
import com.googlecode.lanterna.TerminalSize; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
Screen screen = new TestTerminalFactory(args).createScreen();
screen.startScreen();
MultiWindowTextGUI textGUI = new MultiWindowTextGUI(screen);
textGUI.setEOFWhenNoWindows(true);
try {
final BasicWindow window = new BasicWindow("Button test");
Panel contentArea = new Panel();
contentArea.setLayoutManager(new LinearLayout(Direction.VERTICAL));
contentArea.addComponent(new Button(""));
contentArea.addComponent(new Button("TRE"));
contentArea.addComponent(new Button("Button"));
contentArea.addComponent(new Button("Another button"));
contentArea.addComponent(new EmptySpace(new TerminalSize(5, 1)));
//contentArea.addComponent(new Button("Here is a\nmulti-line\ntext segment that is using \\n"));
contentArea.addComponent(new Button("OK", new Runnable() {
@Override
public void run() {
window.close();
}
}));
window.setComponent(contentArea);
textGUI.addWindowAndWait(window);
}
finally {
screen.stopScreen();
}
}
开发者ID:Truth0906,项目名称:lanterna,代码行数:30,代码来源:MultiButtonTest.java
注:本文中的com.googlecode.lanterna.TerminalSize类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论