Search in sources :

Example 41 with Label

use of com.googlecode.lanterna.gui2.Label in project googleads-java-lib by googleads.

the class CreateLabels method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a competitive exclusion label.
    Label competitiveExclusionLabel = new Label();
    competitiveExclusionLabel.setName("Car company label #" + new Random().nextInt(Integer.MAX_VALUE));
    competitiveExclusionLabel.setTypes(new LabelType[] { LabelType.COMPETITIVE_EXCLUSION });
    // Create an ad unit frequency cap label.
    Label adUnitFrequencyCapLabel = new Label();
    adUnitFrequencyCapLabel.setName("Don't run too often label #" + new Random().nextInt(Integer.MAX_VALUE));
    adUnitFrequencyCapLabel.setTypes(new LabelType[] { LabelType.AD_UNIT_FREQUENCY_CAP });
    // Create the labels on the server.
    Label[] labels = labelService.createLabels(new Label[] { competitiveExclusionLabel, adUnitFrequencyCapLabel });
    for (Label createdLabel : labels) {
        System.out.printf("A label with ID %d and name '%s' was created.%n", createdLabel.getId(), createdLabel.getName());
    }
}
Also used : Random(java.util.Random) LabelServiceInterface(com.google.api.ads.admanager.axis.v202205.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202205.Label)

Example 42 with Label

use of com.googlecode.lanterna.gui2.Label in project googleads-java-lib by googleads.

the class GetActiveLabels method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to select labels.
    StatementBuilder statementBuilder = new StatementBuilder().where("isActive = :isActive").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("isActive", true);
    // Retrieve a small amount of labels at a time, paging through
    // until all labels have been retrieved.
    int totalResultSetSize = 0;
    do {
        LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each label.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Label label : page.getResults()) {
                System.out.printf("%d) Label with ID %d and name '%s' was found.%n", i++, label.getId(), label.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LabelPage(com.google.api.ads.admanager.axis.v202205.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202205.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202205.Label)

Example 43 with Label

use of com.googlecode.lanterna.gui2.Label in project security-lib by ncsa.

the class GUIDemo method testBox.

/**
 * Next is taken verbatim from
 * <a href="https://github.com/mabe02/lanterna/blob/master/src/test/java/com/googlecode/lanterna/tutorial/Tutorial04.java">this laterna tutorial.</a>
 * It will create a groovy floating text window with border. The contents have a few labels and a text box.
 * <h3>Notes</h3>
 * <ul>
 *     <li>Tab between items.</li>
 *     <li>A return activates item</li>
 *     <li>Looks like accelerators are enabled (first character highlighted) but no code to do that, To close, tab to "Close"
 *     button and hit enter.</li>
 * </ul>
 *
 * @param screen
 * @throws IOException
 */
protected static void testBox(Screen screen) throws IOException {
    // ------------------
    // Note that this puts windows on a screen but altering the screen might give strange results,
    // because these GUI components are not aware of it. Think of the screen as working like
    // the Swing JDesktop pane and being a container.
    // All the components (e.g.Panel) are Lanterna NOT Java!
    // ------------------
    final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen);
    /*
                  Creating a new window is relatively uncomplicated, you can optionally supply a title for the window
                   */
    final Window window = new BasicWindow("My Root Window");
    /*
                  The window has no content initially, you need to call setComponent to populate it with something. In this
                  case, and quite often in fact, you'll want to use more than one component so we'll create a composite
                  'Panel' component that can hold multiple sub-components. This is where we decide what the layout manager
                  should be.
                   */
    Panel contentPanel = new Panel(new GridLayout(2));
    /*
         * Lanterna contains a number of built-in layout managers, the simplest one being LinearLayout that simply
         * arranges components in either a horizontal or a vertical line. In this tutorial, we'll use the GridLayout
         * which is based on the layout manager with the same name in SWT. In the constructor above we have
         * specified that we want to have a grid with two columns, below we customize the layout further by adding
         * some spacing between the columns.
         */
    GridLayout gridLayout = (GridLayout) contentPanel.getLayoutManager();
    gridLayout.setHorizontalSpacing(3);
    /*
                  One of the most basic components is the Label, which simply displays a static text. In the example below,
                  we use the layout data field attached to each component to give the layout manager extra hints about how it
                  should be placed. Obviously the layout data has to be created from the same layout manager as the container
                  is using, otherwise it will be ignored.
                   */
    Label title = new Label("This is a label that spans two columns");
    title.setLayoutData(GridLayout.createLayoutData(// Horizontal alignment in the grid cell if the cell is larger than the component's preferred size
    GridLayout.Alignment.BEGINNING, // Vertical alignment in the grid cell if the cell is larger than the component's preferred size
    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));
    contentPanel.addComponent(title);
    /*
                  Since the grid has two columns, we can do something like this to add components when we don't need to
                  customize them any further.
                   */
    contentPanel.addComponent(new Label("Text Box (aligned)"));
    contentPanel.addComponent(new TextBox().setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.BEGINNING, GridLayout.Alignment.CENTER)));
    /*
                  Here is an example of customizing the regular text box component so it masks the content and can work for
                  password input.
                   */
    contentPanel.addComponent(new Label("Password Box (right aligned)"));
    contentPanel.addComponent(new TextBox().setMask('*').setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.END, GridLayout.Alignment.CENTER)));
    /*
                  While we are not going to demonstrate all components here, here is an example of combo-boxes, one that is
                  read-only and one that is editable.
                   */
    contentPanel.addComponent(new Label("Read-only Combo Box (forced size)"));
    List<String> timezonesAsStrings = new ArrayList<>(Arrays.asList(TimeZone.getAvailableIDs()));
    ComboBox<String> readOnlyComboBox = new ComboBox<>(timezonesAsStrings);
    readOnlyComboBox.setReadOnly(true);
    readOnlyComboBox.setPreferredSize(new TerminalSize(20, 1));
    contentPanel.addComponent(readOnlyComboBox);
    contentPanel.addComponent(new Label("Editable Combo Box (filled)"));
    contentPanel.addComponent(new ComboBox<>("Item #1", "Item #2", "Item #3", "Item #4").setReadOnly(false).setLayoutData(GridLayout.createHorizontallyFilledLayoutData(1)));
    /*
                  Some user interactions, like buttons, work by registering callback methods. In this example here, we're
                  using one of the pre-defined dialogs when the button is triggered.
                   */
    contentPanel.addComponent(new Label("Button (centered)"));
    contentPanel.addComponent(new Button("Button", () -> MessageDialog.showMessageDialog(textGUI, "MessageBox", "This is a message box", MessageDialogButton.OK)).setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER)));
    /*
                  Close off with an empty row and a separator, then a button to close the window
                   */
    contentPanel.addComponent(new EmptySpace().setLayoutData(GridLayout.createHorizontallyFilledLayoutData(2)));
    contentPanel.addComponent(new Separator(Direction.HORIZONTAL).setLayoutData(GridLayout.createHorizontallyFilledLayoutData(2)));
    contentPanel.addComponent(new Button("Close", window::close).setLayoutData(GridLayout.createHorizontallyEndAlignedLayoutData(2)));
    /*
                  We now have the content panel fully populated with components. A common mistake is to forget to attach it to
                  the window, so let's make sure to do that.
                   */
    window.setComponent(contentPanel);
    /*
                  Now the window is created and fully populated. As discussed above regarding the threading model, we have the
                  option to fire off the GUI here and then later on decide when we want to stop it. In order for this to work,
                  you need a dedicated UI thread to run all the GUI operations, usually done by passing in a
                  SeparateTextGUIThread object when you create the TextGUI. In this tutorial, we are using the conceptually
                  simpler SameTextGUIThread, which essentially hijacks the caller thread and uses it as the GUI thread until
                  some stop condition is met. The absolutely simplest way to do this is to simply ask lanterna to display the
                  window and wait for it to be closed. This will initiate the event loop and make the GUI functional. In the
                  "Close" button above, we tied a call to the close() method on the Window object when the button is
                  triggered, this will then break the even loop and our call finally returns.
                   */
    textGUI.addWindowAndWait(window);
/*
                  When our call has returned, the window is closed and no longer visible. The screen still contains the last
                  state the TextGUI left it in, so we can easily add and display another window without any flickering. In
                  this case, we want to shut down the whole thing and return to the ordinary prompt. We just need to stop the
                  underlying Screen for this, the TextGUI system does not require any additional disassembly.
                   */
}
Also used : Window(com.googlecode.lanterna.gui2.Window) Label(com.googlecode.lanterna.gui2.Label) ArrayList(java.util.ArrayList) Panel(com.googlecode.lanterna.gui2.Panel) GridLayout(com.googlecode.lanterna.gui2.GridLayout) Button(com.googlecode.lanterna.gui2.Button) MessageDialogButton(com.googlecode.lanterna.gui2.dialogs.MessageDialogButton)

Example 44 with Label

use of com.googlecode.lanterna.gui2.Label in project skywalking-java by apache.

the class MeterIdTest method testTransformTags.

@Test
public void testTransformTags() {
    MeterId meterId = new MeterId("test", MeterType.COUNTER, Arrays.asList(new MeterTag("k1", "v1")));
    // Label message check
    List<Label> labels = meterId.transformTags();
    Assert.assertEquals(1, labels.size());
    final Label label = labels.get(0);
    Assert.assertEquals("k1", label.getName());
    Assert.assertEquals("v1", label.getValue());
    Assert.assertEquals(MeterType.COUNTER, meterId.getType());
    // Must cache the Label message
    final List<Label> cacheLabels = (List<Label>) Whitebox.getInternalState(meterId, "labels");
    Assert.assertEquals(labels, cacheLabels);
    // Check empty tags
    meterId = new MeterId("test", MeterType.COUNTER, Collections.emptyList());
    labels = meterId.transformTags();
    Assert.assertEquals(0, labels.size());
}
Also used : Label(org.apache.skywalking.apm.network.language.agent.v3.Label) List(java.util.List) Test(org.junit.Test)

Aggregations

Label (org.apache.xbean.asm9.Label)9 MethodVisitor (org.apache.xbean.asm9.MethodVisitor)7 Label (com.google.api.ads.admanager.axis.v202108.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202108.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202111.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202111.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202202.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202202.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202205.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202205.LabelServiceInterface)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)4 LabelPage (com.google.api.ads.admanager.axis.v202108.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202111.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202202.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202205.LabelPage)4 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4