本文整理汇总了Java中com.googlecode.lanterna.TerminalSize类的典型用法代码示例。如果您正苦于以下问题:Java TerminalSize类的具体用法?Java TerminalSize怎么用?Java TerminalSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TerminalSize类属于com.googlecode.lanterna包,在下文中一共展示了TerminalSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
}
示例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) {
}
}
}
示例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)));
}
}
示例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;
}
}
}
}
示例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();
}
示例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;
}
}
}
}
示例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));
}
示例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;
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}