/**
   * Create a new tab to the FlexiBar, with the specified title and the specified component inside
   * the tab.
   *
   * @param title the title of the tab to be added
   * @param comp the component inserted in the tab
   */
  public void add(String title, JComponent comp) {
    JButton button = new JButton(title);
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            System.out.println("click");
            setSelected((JButton) arg0.getSource());
          }
        });
    button.setMinimumSize(new Dimension(this.B_WIDTH, this.B_HEIGHT));
    button.setMaximumSize(new Dimension(this.B_WIDTH, this.B_HEIGHT));
    button.setPreferredSize(new Dimension(this.B_WIDTH, this.B_HEIGHT));
    button.setAlignmentX(LEFT_ALIGNMENT);
    comp.setMinimumSize(new Dimension(this.P_WIDTH, this.P_HEIGHT));
    comp.setMaximumSize(new Dimension(this.P_WIDTH, this.P_HEIGHT));
    // comp.setPreferredSize(new Dimension(this.P_WIDTH,this.P_HEIGHT));
    comp.setAlignmentX(LEFT_ALIGNMENT);
    if (currentSelected == -1) {
      comp.setVisible(true);
      currentSelected = 0;
    } else comp.setVisible(false);

    listComponent.add(button);
    listComponent.add(comp);

    panel.add(button);
    panel.add(comp);
  }
Beispiel #2
0
  protected void mapFromObjects() throws RaplaException {
    classificationField.mapFrom(objectList);
    permissionListField.mapFrom(objectList);
    Set<Boolean> values = new HashSet<Boolean>();
    boolean canAdmin = true;
    boolean allPermissions = true;
    boolean internal = false;
    final User user = getUser();

    for (Allocatable alloc : objectList) {
      if (isInternalType(alloc)) {
        internal = true;
      }
      if (((DynamicTypeImpl) alloc.getClassification().getType()).isInternal()) {
        allPermissions = false;
      }
      String annotation = alloc.getAnnotation(ResourceAnnotations.KEY_CONFLICT_CREATION);
      boolean holdBackConflicts =
          annotation != null
              && annotation.equals(ResourceAnnotations.VALUE_CONFLICT_CREATION_IGNORE);
      values.add(holdBackConflicts);
      if (!permissionController.canAdmin(alloc, user)) {
        canAdmin = false;
      }
    }
    if (canAdmin == false) {
      permissionListField.getComponent().setVisible(false);
    }
    if (allPermissions) {
      permissionListField.setPermissionLevels(
          Permission.DENIED,
          Permission.READ_NO_ALLOCATION,
          Permission.READ,
          Permission.ALLOCATE,
          Permission.ALLOCATE_CONFLICTS,
          Permission.EDIT,
          Permission.ADMIN);
    } else {
      permissionListField.setPermissionLevels(Permission.DENIED, Permission.READ);
    }
    if (internal) {
      holdBackConflictPanel.setVisible(false);
      classificationField.setTypeChooserVisible(false);
    } else {
      if (values.size() == 1) {
        Boolean singleValue = values.iterator().next();
        holdBackConflictsField.setValue(singleValue);
      }
      if (values.size() > 1) {
        holdBackConflictsField.setFieldForMultipleValues();
      }
      holdBackConflictPanel.setVisible(true);
      classificationField.setTypeChooserVisible(true);
    }
  }
  /**
   * Sets the window title pane -- the JComponent used to provide a plaf a way to override the
   * native operating system's window title pane with one whose look and feel are controlled by the
   * plaf. The plaf creates and sets this value; the default is null, implying a native operating
   * system window title pane.
   *
   * @param content the <code>JComponent</code> to use for the window title pane.
   */
  private void setTitlePane(JRootPane root, JComponent titlePane) {
    JLayeredPane layeredPane = root.getLayeredPane();
    JComponent oldTitlePane = getTitlePane();

    if (oldTitlePane != null) {
      oldTitlePane.setVisible(false);
      layeredPane.remove(oldTitlePane);
    }
    if (titlePane != null) {
      layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
      titlePane.setVisible(true);
    }
    this.titlePane = titlePane;
  }
Beispiel #4
0
    public ProgressBarIndicatingComponent() {
      progress.setIndeterminate(true);
      progress.setStringPainted(true);

      component = flowLayout(progress, button("Cancel", this::cancel));
      component.setVisible(false);
    }
Beispiel #5
0
  public void showDialog(JComponent dialog) {
    closeDialog();

    JRootPane rootPane = SwingUtilities.getRootPane(mainPanel);
    if (rootPane == null) {
      log.severe("could not find root pane for viewer to show dialog " + dialog);
    } else {
      JLayeredPane layeredPane = rootPane.getLayeredPane();
      Dimension d = dialog.getPreferredSize();
      if (dialogPanel == null) {
        dialogPanel = new DialogPanel(this, new BorderLayout());
      }
      Insets insets = dialogPanel.getInsets();
      int width = viewerPanel.getWidth() - insets.left - insets.right;
      int height = viewerPanel.getHeight() - insets.top - insets.bottom;
      if (d.width > width) {
        d.width = width;
      }
      if (d.height > height) {
        d.height = height;
      }
      dialogPanel.add(dialog, BorderLayout.CENTER);

      dialogPanel.setBounds(
          ((width - d.width) >> 1) + insets.left,
          ((height - d.height) >> 1) + insets.top,
          d.width + insets.left + insets.right,
          d.height + insets.top + insets.bottom);
      dialog.setVisible(true);
      layeredPane.add(dialogPanel, DIALOG_LAYER);
      currentDialog = dialog;
      mainPanel.repaint();
    }
  }
Beispiel #6
0
  public void mouseReleased(java.awt.event.MouseEvent e) {
    if (e.isPopupTrigger()) {
      doPopup(e);
      return;
    }
    if (org.nlogo.awt.Mouse.hasButton1(e)) {
      java.awt.Point p = e.getPoint();
      java.awt.Rectangle rect = this.getBounds();

      p.x += rect.x;
      p.y += rect.y;

      selectionRect = null;
      glassPane.setVisible(false);

      if (newWidget != null) {
        newWidget.selected(true);
        newWidget.foreground();
        newWidget.isNew(true);
        new org.nlogo.window.Events.EditWidgetEvent(null).raise(this);
        newWidget.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
        newWidget.isNew(false);
        newWidget = null;
      }
    }
  }
Beispiel #7
0
 @Override
 public void setVisible(boolean visible) {
   super.setVisible(visible);
   if (visible) {
     timer.start();
   } else {
     timer.stop();
   }
 }
  /** Hides the popup */
  public void hidePopup() {
    // Only hide the popup if the glass pane is
    // visible (i.e. if the popup is being displayed)
    if (glassPane.isVisible() == true) {
      glassPane.setVisible(false);

      firePopupClosedEvent();
    }
  }
Beispiel #9
0
 public void setVisible(boolean bShow, String title) {
   if (bShow) {
     String strDir = "";
     String strFreq = "";
     String strTraynum = "";
     m_strHelpFile = getHelpFile(title);
     String strSampleName = getSampleName(title);
     String frameBounds = getFrameBounds(title);
     StringTokenizer tok = new QuotedStringTokenizer(title);
     if (tok.hasMoreTokens()) strDir = tok.nextToken();
     if (tok.hasMoreTokens()) strFreq = tok.nextToken();
     if (tok.hasMoreTokens()) strTraynum = tok.nextToken();
     else {
       try {
         Integer.parseInt(strDir);
         // if strdir is number, then strdir is empty, and the
         // strfreq is the number
         strTraynum = strFreq;
         strFreq = strDir;
         strDir = "";
       } catch (Exception e) {
       }
     }
     try {
       setTitle(gettitle(strFreq));
       m_lblSampleName.setText("3");
       boolean bVast = isVast(strTraynum);
       CardLayout layout = (CardLayout) m_pnlSampleName.getLayout();
       if (!bVast) {
         if (strSampleName == null) {
           strSampleName = getSampleName(strDir, strTraynum);
         }
         m_lblSampleName.setText(strSampleName);
         layout.show(m_pnlSampleName, OTHER);
       } else {
         m_strDir = strDir;
         setTrays();
         layout.show(m_pnlSampleName, VAST);
         m_trayTimer.start();
       }
       boolean bSample = bVast || !strSampleName.trim().equals("");
       m_pnlSampleName.setVisible(bSample);
       m_lblLogin.setForeground(getBackground());
       m_lblLogin.setVisible(false);
       m_passwordField.setText("");
       m_passwordField.setCaretPosition(0);
     } catch (Exception e) {
       Messages.writeStackTrace(e);
     }
     setBounds(frameBounds);
     ExpPanel exp = Util.getActiveView();
     if (exp != null) exp.waitLogin(true);
   }
   writePersistence();
   setVisible(bShow);
 }
Beispiel #10
0
 public void addComponent(JComponent c) {
   components.add(c);
   c.doLayout();
   visibleComponent = c;
   add(c, BorderLayout.CENTER);
   for (int i = 0; i < components.size(); i++) {
     components.get(i).setVisible(false);
   }
   c.setVisible(true);
 }
Beispiel #11
0
 public static void ynstrument(String path) {
   Jynstrument it = JynstrumentFactory.createInstrument(path, _jynstrumentSpace);
   if (it == null) {
     log.error("Error while creating Jynstrument {}", path);
     return;
   }
   ThrottleFrame.setTransparent(it);
   it.setVisible(true);
   _jynstrumentSpace.setVisible(true);
   _jynstrumentSpace.add(it);
 }
Beispiel #12
0
  @Override
  public void setParent(final JComponent parent) {
    SwingUtilities.invokeLater(
        () -> {
          final JScrollPane scrollPane = new JScrollPane(tree);
          scrollPane.setAutoscrolls(true);
          scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

          parent.setVisible(false);
          parent.setLayout(new MigLayout("ins 0, fill"));
          parent.add(scrollPane, "grow");
          parent.setFocusable(false);
          parent.setVisible(true);

          setColours();

          eventBus.subscribe(this);
          swingEventBus.subscribe(this);
          redoTreeView();
        });
  }
Beispiel #13
0
 final void closeDialog() {
   if (currentDialog != null) {
     JRootPane rootPane = SwingUtilities.getRootPane(mainPanel);
     if (rootPane != null) {
       JLayeredPane layeredPane = rootPane.getLayeredPane();
       layeredPane.remove(dialogPanel);
       currentDialog.setVisible(false);
       currentDialog = null;
       mainPanel.repaint();
     }
   }
 }
Beispiel #14
0
 public WidgetPanel(GUIWorkspace workspace) {
   this.workspace = workspace;
   setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.CROSSHAIR_CURSOR));
   setOpaque(true);
   setBackground(java.awt.Color.WHITE);
   addMouseListener(this);
   addMouseMotionListener(this);
   addFocusListener(this);
   setAutoscrolls(true);
   glassPane.setOpaque(false);
   glassPane.setVisible(false);
   add(glassPane, DRAG_LAYER);
 }
 private void setMoreVisibility(boolean b) {
   showingMore = b;
   for (String key : keysInMoreSection) {
     keyKeyComponentMap.get(key).setVisible(b && keysVisible);
     keyValueComponentMap.get(key).setVisible(b);
     for (JComponent c : keyExtraComponentsMap.get(key)) {
       c.setVisible(b);
     }
     // close opened sub components in more if closing more
     if (!b && keyDetailComponentMap.get(key).isVisible()) {
       keyDetailComponentMap.get(key).setVisible(false);
     }
   }
 }
Beispiel #16
0
  /** Update the style bar visibility. */
  public void updateStyleBarVisibility() {

    if (!isVisible()) return;

    styleBarPanel.setVisible(isStyleBarVisible());
    updateToggleStyleBarButtons();
    updateTitleBar();

    if (isStyleBarVisible()) {
      setStyleBar();
      styleBar.setVisible(showStyleBar);
      styleBarButtonPanel.setVisible(!titlePanel.isVisible());
    }
  }
  /** Builds the GUI of the page. */
  private void buildGui() {
    final Box toolBarsBox = Box.createVerticalBox();
    addNorth(toolBarsBox);

    final XToolBar infoBar = new XToolBar();
    toolBarsBox.add(infoBar);
    infoBar.add(
        new XLabel(
                "<html>On this page you can view and install the available <b>Official</b> external modules."
                    + " <b><font color='red'>Restart is required when changes are made!</font></b></html>")
            .verticalBorder(5));
    infoBar.finalizeLayout();

    final ToolBarForTable toolBar = new ToolBarForTable(table);
    toolBarsBox.add(toolBar);
    toolBar.addSelectInfoLabel("Select a Module.");
    toolBar.addSelEnabledButton(enableUpdateAction);
    toolBar.addSeparator();
    toolBar.addSelEnabledButton(disableUpdateAction);
    toolBar.addSeparator();
    toolBar.add(new XLabel(LHelps.EXTERNAL_MODULES.title).leftBorder(20));
    toolBar.add(new HelpIcon(LHelps.EXTERNAL_MODULES).leftBorder(2));
    toolBar.addSeparator();
    toolBar.add(new XLabel(LHelps.OFFICIAL_EXTERNAL_MODULES.title));
    toolBar.add(new HelpIcon(LHelps.OFFICIAL_EXTERNAL_MODULES).leftBorder(2));
    toolBar.finalizeLayout();

    final Box viewsBox = Box.createVerticalBox();
    viewsBox.add(waitInfoWrapper);
    if (LEnv.APP_STARTED.get())
      waitInfoWrapper.setVisible(false); // App started, we surely have what we need
    else tableWrapperBox.setVisible(false);
    viewsBox.add(tableWrapperBox);
    addCenter(viewsBox);

    rebuildTable();
  }
Beispiel #18
0
    private void processStateChangeIfNecessary(
        @NotNull Point mouseScreenLocation, boolean mouseEntered) {
      // Don't show 'view quick doc' buttons if docked quick doc control is already active.
      if (myDocumentationManager.hasActiveDockedDocWindow()) {
        return;
      }

      // Skip event triggered when mouse leaves action button area.
      if (!mouseEntered
          && new Rectangle(getLocationOnScreen(), getSize()).contains(mouseScreenLocation)) {
        return;
      }
      for (JComponent button : myButtons) {
        button.setVisible(mouseEntered);
      }
    }
  @Override
  protected JComponent decorateCheckBox(final DCCheckBox<InputColumn<?>> checkBox) {
    final SourceColumnComboBox sourceColumnComboBox;
    final InputColumn<?> inputColumn = checkBox.getValue();
    if (_mappedColumnComboBoxes.containsKey(inputColumn)) {
      sourceColumnComboBox = _mappedColumnComboBoxes.get(inputColumn);
    } else {
      sourceColumnComboBox = createComboBox(inputColumn, null);
    }

    final JComponent decoratedSourceColumnComboBox =
        decorateSourceColumnComboBox(inputColumn, sourceColumnComboBox);

    checkBox.addListenerToHead(
        new DCCheckBox.Listener<InputColumn<?>>() {
          @Override
          public void onItemSelected(InputColumn<?> item, boolean selected) {
            _sourceColumnUpdating = true;
            decoratedSourceColumnComboBox.setVisible(selected);
          }
        });
    checkBox.addListener(
        new DCCheckBox.Listener<InputColumn<?>>() {
          @Override
          public void onItemSelected(InputColumn<?> item, boolean selected) {
            if (isBatchUpdating()) {
              return;
            }
            _mappedColumnNamesPropertyWidget.fireValueChanged();
            _sourceColumnUpdating = false;
          }
        });

    Table table = _tableRef.get();
    if (table != null) {
      sourceColumnComboBox.setModel(table);
    }

    decoratedSourceColumnComboBox.setVisible(checkBox.isSelected());

    final DCPanel panel = new DCPanel();
    panel.setLayout(new BorderLayout());
    panel.add(checkBox, BorderLayout.CENTER);
    panel.add(decoratedSourceColumnComboBox, BorderLayout.EAST);
    return panel;
  }
Beispiel #20
0
    QuickDocInfoPane(
        @NotNull PsiElement documentationAnchor,
        @NotNull PsiElement elementUnderMouse,
        @NotNull JComponent baseDocControl) {
      myBaseDocControl = baseDocControl;

      PresentationFactory presentationFactory = new PresentationFactory();
      for (AbstractDocumentationTooltipAction action : ourTooltipActions) {
        Icon icon = action.getTemplatePresentation().getIcon();
        Dimension minSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
        myButtons.add(
            new ActionButton(
                action,
                presentationFactory.getPresentation(action),
                IdeTooltipManager.IDE_TOOLTIP_PLACE,
                minSize));
        action.setDocInfo(documentationAnchor, elementUnderMouse);
      }
      Collections.reverse(myButtons);

      setPreferredSize(baseDocControl.getPreferredSize());
      setMaximumSize(baseDocControl.getMaximumSize());
      setMinimumSize(baseDocControl.getMinimumSize());
      setBackground(baseDocControl.getBackground());

      add(baseDocControl, Integer.valueOf(0));
      int minWidth = 0;
      int minHeight = 0;
      int buttonWidth = 0;
      for (JComponent button : myButtons) {
        button.setBorder(null);
        button.setBackground(baseDocControl.getBackground());
        add(button, Integer.valueOf(1));
        button.setVisible(false);
        Dimension preferredSize = button.getPreferredSize();
        minWidth += preferredSize.width;
        minHeight = Math.max(minHeight, preferredSize.height);
        buttonWidth = Math.max(buttonWidth, preferredSize.width);
      }
      myButtonWidth = buttonWidth;

      int margin = 2;
      myMinWidth = minWidth + margin * 2 + (myButtons.size() - 1) * BUTTON_HGAP;
      myMinHeight = minHeight + margin * 2;
    }
Beispiel #21
0
  public void mouseDragged(java.awt.event.MouseEvent e) {
    if (!org.nlogo.awt.Mouse.hasButton1(e)) {
      return;
    }
    java.awt.Point p = e.getPoint();
    java.awt.Rectangle rect = this.getBounds();

    p.x += rect.x;
    p.y += rect.y;

    if (newWidget != null) {
      if (workspace.snapOn()) {
        startDragPoint.x = (startDragPoint.x / GRID_SNAP) * GRID_SNAP;
        startDragPoint.y = (startDragPoint.y / GRID_SNAP) * GRID_SNAP;
      }
      java.awt.Point p2 =
          restrictDrag(
              new java.awt.Point(e.getX() - startDragPoint.x, e.getY() - startDragPoint.y),
              newWidget);
      newWidget.setLocation(startDragPoint.x + p2.x, startDragPoint.y + p2.y);
    } else if (null != startDragPoint) {
      if (!glassPane.isVisible()) {
        glassPane.setBounds(0, 0, getWidth(), getHeight());
        glassPane.setVisible(true);
      }
      scrollRectToVisible(new java.awt.Rectangle(e.getX() - 20, e.getY() - 20, 40, 40));
      java.awt.Rectangle oldSelectionRect = selectionRect;
      int x = StrictMath.min(getWidth(), StrictMath.max(e.getX(), 0));
      int y = StrictMath.min(getHeight(), StrictMath.max(e.getY(), 0));
      selectionRect =
          new java.awt.Rectangle(
              StrictMath.min(startDragPoint.x, x),
              StrictMath.min(startDragPoint.y, y),
              StrictMath.abs(x - startDragPoint.x),
              StrictMath.abs(y - startDragPoint.y));
      selectWidgets(selectionRect);
      if (oldSelectionRect != null) {
        glassPane.repaint(oldSelectionRect);
      }
      glassPane.repaint(selectionRect);
    }
  }
Beispiel #22
0
  /**
   * Updates the contents of the panel with the provided index.
   *
   * @param index the index descriptor to be used to update the panel.
   */
  public void update(IndexDescriptor index) {
    ignoreCheckSave = true;
    setPrimaryValid(lEntryLimit);
    setPrimaryValid(lType);
    name.setText(index.getName());
    backendName.setText(index.getBackend().getBackendID());
    titlePanel.setDetails(LocalizableMessage.raw(index.getName()));
    entryLimit.setText(String.valueOf(index.getEntryLimit()));
    approximate.setSelected(false);
    equality.setSelected(false);
    ordering.setSelected(false);
    substring.setSelected(false);
    presence.setSelected(false);
    for (IndexTypeDescriptor type : index.getTypes()) {
      switch (type) {
        case APPROXIMATE:
          approximate.setSelected(true);
          break;
        case PRESENCE:
          presence.setSelected(true);
          break;
        case EQUALITY:
          equality.setSelected(true);
          break;
        case ORDERING:
          ordering.setSelected(true);
          break;
        case SUBSTRING:
          substring.setSelected(true);
          break;
      }
    }

    JComponent[] comps = {entryLimit, lType, typesPanel, lEntryLimit};

    for (JComponent comp : comps) {
      comp.setVisible(!index.isDatabaseIndex());
    }

    AttributeType attr = index.getAttributeType();
    repopulateTypesPanel(attr);

    if (index.isDatabaseIndex()) {
      entryLimit.setText("");
    }
    saveChanges.setVisible(!index.isDatabaseIndex());
    deleteIndex.setVisible(!index.isDatabaseIndex());
    if (index.isDatabaseIndex()) {
      Utilities.setWarningLabel(warning, NON_CONFIGURABLE_INDEX);
      warning.setVisible(true);
    } else if (getInfo() != null) {
      if (getInfo().mustReindex(index)) {
        Utilities.setWarningLabel(warning, INDEX_MODIFIED);
        warning.setVisible(true);
        warning.setVerticalTextPosition(SwingConstants.TOP);
      } else {
        warning.setVisible(false);
      }
    }
    this.index = index;

    ignoreCheckSave = false;
    checkSaveButton();

    scrollListener.updateBorder();
  }
 @Override
 public void setVisible(boolean enabled) {
   super.setVisible(enabled);
 }
 private void updateToolbarVisibility() {
   myToolbar.setVisible(myUISettings.SHOW_MAIN_TOOLBAR && myWelcomeScreen == null);
 }
  /** Rebuilds the table. */
  private void rebuildTable() {
    table.saveSelection(extModRefColIdx);

    final ModulesBean modules = ScelightLauncher.INSTANCE().getModules();

    // Only build table if modules bean has been retrieved.
    if (waitInfoWrapper.isVisible()) {
      if (modules == null) {
        if (recheckTimer == null) {
          // Start timer to periodically check if modules been has been retrieved
          recheckTimer =
              new Timer(
                  250,
                  new ActionAdapter() {
                    @Override
                    public void actionPerformed(final ActionEvent event) {
                      rebuildTable();
                    }
                  });
          recheckTimer.start();
        }
        return;
      } else {
        if (recheckTimer != null) recheckTimer.stop();
        waitInfoWrapper.setVisible(false);
        tableWrapperBox.setVisible(true);
      }
    }

    final Vector<Vector<Object>> data = new Vector<>();

    final OffExtModConfsBean offExtModConfsBean =
        LEnv.LAUNCHER_SETTINGS.get(LSettings.OFF_EXT_MOD_CONFS);
    if (modules.getExtModRefList() != null) // This might be null if no internet connection...
    for (final ExtModRefBean emr : modules.getExtModRefList()) {
        final OffExtModConfBean conf = offExtModConfsBean.getModuleConfForFolder(emr.getFolder());

        final StringBuilder authorsBuilder = new StringBuilder();
        for (final PersonBean author : emr.getAuthorList()) {
          if (authorsBuilder.length() > 0) authorsBuilder.append(", ");
          authorsBuilder.append(LEnv.LANG.formatPersonName(author.getPersonName()));
        }

        data.add(
            LUtils.vector(
                emr,
                emr.getIcon(),
                emr.getName(),
                conf == null ? Boolean.FALSE : conf.getAutoUpdate(),
                authorsBuilder.toString(),
                LUtils.tryMakingUrl(emr.getHomePage()),
                emr.getShortDesc()));
      }

    table
        .getXTableModel()
        .setDataVector(
            data,
            LUtils.vector(
                "ExtModRef",
                "I",
                "Name",
                "Auto-updated?",
                "Author",
                "Home page",
                "Short description"));

    extModRefColIdx = 0;
    final int autoUpdateColIdx = 3;
    table.getXTableRowSorter().setColumnDefaultDesc(autoUpdateColIdx, true);
    table.getColumnModel().removeColumn(table.getColumnModel().getColumn(extModRefColIdx));
    table.packColumnsExceptLast();

    table.restoreSelection(extModRefColIdx);
  }
Beispiel #26
0
  /**
   * Fill the given panel by adding all necessary components to the different locations.
   *
   * @param panel The container to fill. Must have an BorderLayout.
   */
  public void fillPanel(Container panel) {
    panel.add(this, BorderLayout.CENTER);

    /** sideToolBar: add map modes icons */
    if (Main.pref.getBoolean("sidetoolbar.mapmodes.visible", true)) {
      toolBarActions.setAlignmentX(0.5f);
      toolBarActions.setInheritsPopupMenu(true);
      sideToolBar.add(toolBarActions);
      listAllMapModesButton.setAlignmentX(0.5f);
      listAllMapModesButton.setBorder(null);
      listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN));
      listAllMapModesButton.setInheritsPopupMenu(true);
      sideToolBar.add(listAllMapModesButton);
    }

    /** sideToolBar: add toggle dialogs icons */
    if (Main.pref.getBoolean("sidetoolbar.toggledialogs.visible", true)) {
      ((JToolBar) sideToolBar).addSeparator(new Dimension(0, 18));
      toolBarToggle.setAlignmentX(0.5f);
      toolBarToggle.setInheritsPopupMenu(true);
      sideToolBar.add(toolBarToggle);
      listAllToggleDialogsButton.setAlignmentX(0.5f);
      listAllToggleDialogsButton.setBorder(null);
      listAllToggleDialogsButton.setFont(
          listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN));
      listAllToggleDialogsButton.setInheritsPopupMenu(true);
      sideToolBar.add(listAllToggleDialogsButton);
    }

    /** sideToolBar: add dynamic popup menu */
    sideToolBar.setComponentPopupMenu(
        new JPopupMenu() {
          static final int staticMenuEntryCount = 2;
          JCheckBoxMenuItem doNotHide =
              new JCheckBoxMenuItem(
                  new AbstractAction(tr("Do not hide toolbar")) {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
                      Main.pref.put("sidetoolbar.always-visible", sel);
                    }
                  });

          {
            addPopupMenuListener(
                new PopupMenuListener() {
                  @Override
                  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    final Object src = ((JPopupMenu) e.getSource()).getInvoker();
                    if (src instanceof IconToggleButton) {
                      insert(new Separator(), 0);
                      insert(
                          new AbstractAction() {
                            {
                              putValue(NAME, tr("Hide this button"));
                              putValue(
                                  SHORT_DESCRIPTION,
                                  tr("Click the arrow at the bottom to show it again."));
                            }

                            @Override
                            public void actionPerformed(ActionEvent e) {
                              ((IconToggleButton) src).setButtonHidden(true);
                              validateToolBarsVisibility();
                            }
                          },
                          0);
                    }
                    doNotHide.setSelected(Main.pref.getBoolean("sidetoolbar.always-visible", true));
                  }

                  @Override
                  public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    while (getComponentCount() > staticMenuEntryCount) {
                      remove(0);
                    }
                  }

                  @Override
                  public void popupMenuCanceled(PopupMenuEvent e) {}
                });

            add(
                new AbstractAction(tr("Hide edit toolbar")) {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    Main.pref.put("sidetoolbar.visible", false);
                  }
                });
            add(doNotHide);
          }
        });
    ((JToolBar) sideToolBar).setFloatable(false);

    /** sideToolBar: decide scroll- and visibility */
    if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
      final ScrollViewport svp = new ScrollViewport(sideToolBar, ScrollViewport.VERTICAL_DIRECTION);
      svp.addMouseWheelListener(
          new MouseWheelListener() {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
              svp.scroll(0, e.getUnitsToScroll() * 5);
            }
          });
      sideToolBar = svp;
    }
    sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));
    sidetoolbarPreferencesChangedListener =
        new Preferences.PreferenceChangedListener() {
          @Override
          public void preferenceChanged(PreferenceChangeEvent e) {
            if ("sidetoolbar.visible".equals(e.getKey())) {
              sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));
            }
          }
        };
    Main.pref.addPreferenceChangeListener(sidetoolbarPreferencesChangedListener);

    /** sideToolBar: add it to the panel */
    panel.add(sideToolBar, BorderLayout.WEST);

    /** statusLine: add to panel */
    if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
      panel.add(statusLine, BorderLayout.SOUTH);
    }
  }
  public static void main(String args[]) {
    JComponent ch = new JComponent() {};
    ch.getAccessibleContext();
    ch.isFocusTraversable();
    ch.setEnabled(false);
    ch.setEnabled(true);
    ch.requestFocus();
    ch.requestFocusInWindow();
    ch.getPreferredSize();
    ch.getMaximumSize();
    ch.getMinimumSize();
    ch.contains(1, 2);
    Component c1 = ch.add(new Component() {});
    Component c2 = ch.add(new Component() {});
    Component c3 = ch.add(new Component() {});
    Insets ins = ch.getInsets();
    ch.getAlignmentY();
    ch.getAlignmentX();
    ch.getGraphics();
    ch.setVisible(false);
    ch.setVisible(true);
    ch.setForeground(Color.red);
    ch.setBackground(Color.red);
    for (String font : Toolkit.getDefaultToolkit().getFontList()) {
      for (int j = 8; j < 17; j++) {
        Font f1 = new Font(font, Font.PLAIN, j);
        Font f2 = new Font(font, Font.BOLD, j);
        Font f3 = new Font(font, Font.ITALIC, j);
        Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);

        ch.setFont(f1);
        ch.setFont(f2);
        ch.setFont(f3);
        ch.setFont(f4);

        ch.getFontMetrics(f1);
        ch.getFontMetrics(f2);
        ch.getFontMetrics(f3);
        ch.getFontMetrics(f4);
      }
    }
    ch.enable();
    ch.disable();
    ch.reshape(10, 10, 10, 10);
    ch.getBounds(new Rectangle(1, 1, 1, 1));
    ch.getSize(new Dimension(1, 2));
    ch.getLocation(new Point(1, 2));
    ch.getX();
    ch.getY();
    ch.getWidth();
    ch.getHeight();
    ch.isOpaque();
    ch.isValidateRoot();
    ch.isOptimizedDrawingEnabled();
    ch.isDoubleBuffered();
    ch.getComponentCount();
    ch.countComponents();
    ch.getComponent(1);
    ch.getComponent(2);
    Component[] cs = ch.getComponents();
    ch.getLayout();
    ch.setLayout(new FlowLayout());
    ch.doLayout();
    ch.layout();
    ch.invalidate();
    ch.validate();
    ch.remove(0);
    ch.remove(c2);
    ch.removeAll();
    ch.preferredSize();
    ch.minimumSize();
    ch.getComponentAt(1, 2);
    ch.locate(1, 2);
    ch.getComponentAt(new Point(1, 2));
    ch.isFocusCycleRoot(new Container());
    ch.transferFocusBackward();
    ch.setName("goober");
    ch.getName();
    ch.getParent();
    ch.getGraphicsConfiguration();
    ch.getTreeLock();
    ch.getToolkit();
    ch.isValid();
    ch.isDisplayable();
    ch.isVisible();
    ch.isShowing();
    ch.isEnabled();
    ch.enable(false);
    ch.enable(true);
    ch.enableInputMethods(false);
    ch.enableInputMethods(true);
    ch.show();
    ch.show(false);
    ch.show(true);
    ch.hide();
    ch.getForeground();
    ch.isForegroundSet();
    ch.getBackground();
    ch.isBackgroundSet();
    ch.getFont();
    ch.isFontSet();
    Container c = new Container();
    c.add(ch);
    ch.getLocale();
    for (Locale locale : Locale.getAvailableLocales()) ch.setLocale(locale);

    ch.getColorModel();
    ch.getLocation();

    boolean exceptions = false;
    try {
      ch.getLocationOnScreen();
    } catch (IllegalComponentStateException e) {
      exceptions = true;
    }
    if (!exceptions)
      throw new RuntimeException("IllegalComponentStateException did not occur when expected");

    ch.location();
    ch.setLocation(1, 2);
    ch.move(1, 2);
    ch.setLocation(new Point(1, 2));
    ch.getSize();
    ch.size();
    ch.setSize(1, 32);
    ch.resize(1, 32);
    ch.setSize(new Dimension(1, 32));
    ch.resize(new Dimension(1, 32));
    ch.getBounds();
    ch.bounds();
    ch.setBounds(10, 10, 10, 10);
    ch.setBounds(new Rectangle(10, 10, 10, 10));
    ch.isLightweight();
    ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
    ch.getCursor();
    ch.isCursorSet();
    ch.inside(1, 2);
    ch.contains(new Point(1, 2));
    ch.isFocusable();
    ch.setFocusable(true);
    ch.setFocusable(false);
    ch.transferFocus();
    ch.getFocusCycleRootAncestor();
    ch.nextFocus();
    ch.transferFocusUpCycle();
    ch.hasFocus();
    ch.isFocusOwner();
    ch.toString();
    ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    ch.setComponentOrientation(ComponentOrientation.UNKNOWN);
    ch.getComponentOrientation();
  }
  /**
   * Causes the popup to be displayed at the specified location.
   *
   * @param component The component whose cooredinate system is to be used.
   * @param x The horizontal location of the popup
   * @param y The vertical location of the popup.
   */
  public void showPopup(JComponent component, int x, int y) {
    // Get the root (JFrame probably)
    Component rootComp = SwingUtilities.getRoot(component);

    // Determine where to place the popup
    // (Left or right, top or bottom of the mouse cursor
    // We want to fit the popup within the top level frame

    int componentMaxX = (int) rootComp.getSize().width;

    int componentMaxY = (int) rootComp.getSize().height;

    int xPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).x;

    int yPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).y;

    // Display to the right of the mouse cursor, unless
    // there is not enough room
    int deltaX = xPosOnRoot + content.getWidth() - componentMaxX;

    if (deltaX > 0) {
      xPosOnRoot -= deltaX;

      if (xPosOnRoot < 0) {
        xPosOnRoot = 0;
      }
    }

    int deltaY = yPosOnRoot + content.getHeight() - componentMaxY;

    if (deltaY > 0) {
      yPosOnRoot -= deltaY;

      if (yPosOnRoot < 0) {
        yPosOnRoot = 0;
      }
    }

    // Convert root pos back to component pos

    int xPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).x;

    int yPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).y;

    JRootPane rootPane = component.getRootPane();

    rootPane.setGlassPane(glassPane);

    // Convert the mouse point from the invoking component coordinate
    // system to the glassPane coordinate system
    Point pt = SwingUtilities.convertPoint(component, xPos, yPos, glassPane);

    // Set the location of the popup in the glass pane
    content.setLocation(pt);

    // Show the glass pane.
    glassPane.setVisible(true);

    // If the popup is set to hide automatically after a specified
    // amount of time, then reset the timer.
    if (HIDE_ON_TIMER == true) {
      timer.stop();

      timer.start();
    }
  }
 /**
  * Set Visible
  *
  * @param visible true if field is to be shown
  */
 public void setVisible(boolean visible) {
   super.setVisible(visible);
 }
Beispiel #30
0
  protected void dolayout(String strDir, String strFreq, String strTraynum) {
    // TopBar
    String strTitle = gettitle(strFreq);
    Color color = DisplayOptions.getColor("Heading3");

    // Center Panel
    JPanel panelCenter = new JPanel(new GridBagLayout());
    GridBagConstraints gbc =
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.2,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0);
    ImageIcon icon = getImageIcon();
    // panelCenter.add(new JLabel(icon));
    addComp(panelCenter, new JLabel(icon), gbc, 0, 0);
    strTitle = getSampleName(strDir, strTraynum);
    m_lblSampleName = new JLabel(strTitle);
    if (strTitle == null || !strTitle.trim().equals("")) strTitle = "3";
    Font font = m_lblSampleName.getFont();
    font = DisplayOptions.getFont(font.getName(), Font.BOLD, 300);
    m_lblSampleName.setFont(font);
    m_lblSampleName.setForeground(color);
    // panelCenter.add(m_lblSampleName);
    m_pnlSampleName = new JPanel(new CardLayout());
    m_pnlSampleName.add(m_lblSampleName, OTHER);
    addComp(panelCenter, m_pnlSampleName, gbc, 1, 0);
    m_pnlSampleName.setVisible(false);
    m_pnlTrays = new JPanel(new GridLayout(1, 0));
    // Vast panels
    VBox pnlVast1 = new VBox(m_pnlTrays, "1");
    m_pnlTrays.add(pnlVast1);
    m_pnlVast[0] = pnlVast1;
    VBox pnlVast2 = new VBox(m_pnlTrays, "2");
    m_pnlTrays.add(pnlVast2);
    m_pnlVast[1] = pnlVast2;
    VBox pnlVast3 = new VBox(m_pnlTrays, "3");
    m_pnlTrays.add(pnlVast3);
    m_pnlVast[2] = pnlVast3;
    VBox pnlVast4 = new VBox(m_pnlTrays, "4");
    m_pnlTrays.add(pnlVast4);
    m_pnlVast[3] = pnlVast4;
    VBox pnlVast5 = new VBox(m_pnlTrays, "5");
    m_pnlTrays.add(pnlVast5);
    m_pnlVast[4] = pnlVast5;
    m_pnlSampleName.add(m_pnlTrays, VAST);

    // Login Panel
    JPanel panelThird = new JPanel(new BorderLayout());
    JPanel panelLogin = new JPanel(new GridBagLayout());
    gbc = new GridBagConstraints();
    panelThird.add(panelLogin);
    Object[] aStrUser = getOperators();
    m_cmbUser = new JComboBox(aStrUser);
    BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();
    m_cmbUser.setRenderer(renderer);
    m_cmbUser.setEditable(true);
    m_passwordField = new JPasswordField();
    // *Warning, working around a Java problem*
    // When we went to the T3500 running Redhat 5.3, the JPasswordField
    // fields sometimes does not allow ANY entry of characters.  Setting
    // the enableInputMethods() to true fixed this problem.  There are
    // comments that indicate that this could cause the typed characters
    // to be visible.  I have not found that to be a problem.
    // This may not be required in the future, or could cause characters
    // to become visible in the future if Java changes it's code.
    // GRS  8/20/09
    m_passwordField.enableInputMethods(true);

    m_lblLogin = new VLoginLabel(null, "Incorrect username/password \n Please try again ", 0, 0);
    m_lblLogin.setVisible(false);
    okButton.setActionCommand("enter");
    okButton.addActionListener(this);
    cancelButton.setActionCommand("cancel");
    cancelButton.addActionListener(this);
    helpButton.setActionCommand("help");
    helpButton.addActionListener(this);
    m_passwordField.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) enterLogin();
          }
        });

    // These is some wierd problem such that sometimes, the vnmrj command
    // area gets the focus and these items in the login box do not get
    // the focus.  Even clicking in these items does not bring focus to
    // them.  Issuing requestFocus() does not bring focus to them.
    // I can however, determing if either the operator entry box or
    // the password box has focus and if neither does, I can unshow and
    // reshow the panel and that fixes the focus.  So, I have added this
    // to the mouseClicked action.  If neither has focus, it will
    // take focus with setVisible false then true.
    comboTextField = m_cmbUser.getEditor().getEditorComponent();
    m_passwordField.addMouseListener(this);
    comboTextField.addMouseListener(this);

    m_lblUsername = new JLabel(Util.getLabel("_Operator"));
    addComp(panelLogin, m_lblUsername, gbc, 0, 0);
    addComp(panelLogin, m_cmbUser, gbc, 1, 0);
    m_lblPassword = new JLabel(Util.getLabel("_Password"));
    addComp(panelLogin, m_lblPassword, gbc, 0, 1);
    addComp(panelLogin, m_passwordField, gbc, 1, 1);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = GridBagConstraints.REMAINDER;
    addComp(panelLogin, m_lblLogin, gbc, 2, 0);
    setPref();

    Container container = getContentPane();
    JPanel panelLoginBox = new JPanel(new BorderLayout());
    panelLoginBox.add(panelCenter, BorderLayout.CENTER);
    panelLoginBox.add(panelThird, BorderLayout.SOUTH);
    container.add(panelLoginBox, BorderLayout.CENTER);
  }