use of com.googlecode.lanterna.gui2.Window in project jbang-catalog by quintesse.
the class lanterna method main.
public static void main(String[] args) {
DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory().setMouseCaptureMode(MouseCaptureMode.CLICK_RELEASE);
try (Screen screen = terminalFactory.createScreen()) {
screen.startScreen();
List<String> timezonesAsStrings = new ArrayList<>(Arrays.asList(TimeZone.getAvailableIDs()));
final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen);
final Window window = new BasicWindow("My Root Window");
Panel contentPanel = new Panel().setLayoutManager(new GridLayout(2).setHorizontalSpacing(3)).addComponent(new Label("This is a label that spans two columns").setLayoutData(GridLayout.createLayoutData(// Horizontal alignment in the grid cell if the cell
GridLayout.Alignment.BEGINNING, // Vertical alignment in the grid cell if the cell
GridLayout.Alignment.BEGINNING, // Give the component extra horizontal space if available
true, // Give the component extra vertical space if available
false, // Horizontal span
2, // Vertical span
1))).addComponent(new Label("Text Box (aligned)")).addComponent(new TextBox().setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.BEGINNING, GridLayout.Alignment.CENTER))).addComponent(new Label("Password Box (right aligned)")).addComponent(new TextBox().setMask('*').setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.END, GridLayout.Alignment.CENTER))).addComponent(new Label("Read-only Combo Box (forced size)")).addComponent(new ComboBox<>(timezonesAsStrings).setReadOnly(true).setPreferredSize(new TerminalSize(20, 1))).addComponent(new Label("Editable Combo Box (filled)")).addComponent(new ComboBox<>("Item #1", "Item #2", "Item #3", "Item #4").setReadOnly(false).setLayoutData(GridLayout.createHorizontallyFilledLayoutData(1))).addComponent(new Label("Button (centered)")).addComponent(new Button("Button", () -> MessageDialog.showMessageDialog(textGUI, "MessageBox", "This is a message box", MessageDialogButton.OK)).setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER))).addComponent(new EmptySpace().setLayoutData(GridLayout.createHorizontallyFilledLayoutData(2))).addComponent(new Separator(Direction.HORIZONTAL).setLayoutData(GridLayout.createHorizontallyFilledLayoutData(2))).addComponent(new Button("Close", window::close).setLayoutData(GridLayout.createHorizontallyEndAlignedLayoutData(2)));
window.setComponent(contentPanel);
window.addWindowListener(new WindowListenerAdapter() {
public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) {
if (keyStroke.getKeyType() == KeyType.Escape) {
window.close();
}
}
});
textGUI.addWindowAndWait(window);
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.googlecode.lanterna.gui2.Window in project security-lib by ncsa.
the class GUIDemo method helloWorld.
public static void helloWorld(Screen screen) {
// Create panel to hold components
Panel panel = new Panel();
panel.setLayoutManager(new GridLayout(2));
panel.addComponent(new Label("Forename"));
panel.addComponent(new TextBox());
panel.addComponent(new Label("Surname"));
panel.addComponent(new TextBox());
// Empty space underneath labels
panel.addComponent(new EmptySpace(new TerminalSize(0, 0)));
panel.addComponent(new Button("Submit"));
// Create window to hold the panel
BasicWindow window = new BasicWindow();
window.setComponent(panel);
// Create gui and start gui
MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
gui.addWindowAndWait(window);
}
use of com.googlecode.lanterna.gui2.Window in project cardgame1 by joey101937.
the class CampaignManager method goToCardAdder.
public static void goToCardAdder() {
Board board = Board.getMainBoard();
board.running = false;
Window window = board.window;
JFrame frame = window.frame;
if (frame == null) {
System.out.println("frame is null");
System.exit(1);
} else {
frame.dispose();
board.running = false;
if (level <= 4)
new CardAdderFrame(4);
else
new CardAdderFrame(2);
// available = true;
}
}
use of com.googlecode.lanterna.gui2.Window in project cardgame1 by joey101937.
the class CampaignManager method returnToInterface.
/**
* ends the current game instance and returns to campaign interface
*/
public static void returnToInterface() {
Board board = Board.getMainBoard();
board.running = false;
Window window = board.window;
JFrame frame = window.frame;
if (frame == null) {
System.out.println("frame is null");
System.exit(1);
} else {
frame.dispose();
board.running = false;
new CampaignInterface();
// available = true;
}
}
use of com.googlecode.lanterna.gui2.Window in project tests by datanucleus.
the class ManagedRelationshipTest method testOneToManyJoinBidirPersistElement.
/**
* Test for management of relations with a 1-N JoinTable bidir where the objects are persisted
* and only the FK side is set.
*/
public void testOneToManyJoinBidirPersistElement() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "true");
Transaction tx = pm.currentTransaction();
try {
tx.begin();
House house = new House(14, "Smith Street");
Window window1 = new Window(100, 200, house);
Window window2 = new Window(600, 200, house);
assertNotNull("Window1 has null House but should be not-null before persist", window1.getHouse());
assertNotNull("Window2 has null House but should be not-null before persist", window2.getHouse());
assertEquals("House has Windows yet should be empty before persist", 0, house.getWindows().size());
pm.makePersistent(window1);
pm.makePersistent(window2);
pm.flush();
// Check that the relation sides are both set
assertSame("Window1 has incorrect House after persist/flush", house, window1.getHouse());
assertSame("Window2 has incorrect House after persist/flush", house, window2.getHouse());
assertEquals("House has incorrect Windows after persist/flush", 2, house.getWindows().size());
tx.commit();
} catch (Exception e) {
LOG.error("Exception thrown persisting 1-N JoinTable bidir with only FK side set", e);
fail("Error in test : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(House.class);
clean(Window.class);
}
}
Aggregations