Exemplo n.º 1
0
 /**
  * Installs the appropriate LayoutManager on the <code>JRootPane</code> to render the window
  * decorations.
  */
 private void installLayout(JRootPane root) {
   if (layoutManager == null) {
     layoutManager = createLayoutManager();
   }
   savedOldLayout = root.getLayout();
   root.setLayout(layoutManager);
 }
Exemplo n.º 2
0
 /** Uninstalls the previously installed <code>LayoutManager</code>. */
 private void uninstallLayout(JRootPane root) {
   if (savedOldLayout != null) {
     root.setLayout(savedOldLayout);
     savedOldLayout = null;
   }
 }
Exemplo n.º 3
0
  /** Build the GUI */
  private void initGUI() {
    // The actual time/date used to fill the time fields
    Calendar calendar = Calendar.getInstance();

    guiSwitches = new LoadSwitchesPanel(loggingClient);

    JRootPane mainPnl = this.getRootPane();
    mainPnl.setLayout(new BorderLayout());

    // The panel with the option of the query
    JPanel optionsPnl = new JPanel();
    GridBagLayout prefsLayout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    optionsPnl.setLayout(prefsLayout);
    // Add all the labels
    JLabel maxLogs = new JLabel("Max num of logs to load:");
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(10, 5, 5, 5);
    optionsPnl.add(maxLogs, c);
    JLabel fromLbl = new JLabel("From:");
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(fromLbl, c);
    JLabel toLbl = new JLabel("To:");
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(toLbl, c);
    JLabel routinNameLbl = new JLabel("Routine name:");
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(routinNameLbl, c);
    JLabel procNameLbl = new JLabel("Process name:");
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(procNameLbl, c);
    JLabel srcNameLbl = new JLabel("Source object:");
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(srcNameLbl, c);
    JLabel minLogType = new JLabel("From type:");
    c.gridx = 0;
    c.gridy = 6;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(minLogType, c);
    JLabel maxLogType = new JLabel("To type:");
    c.gridx = 0;
    c.gridy = 7;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 10, 5);
    optionsPnl.add(maxLogType, c);

    // Add the input widgets
    fromYY = new JTextField(Integer.toString(calendar.get(Calendar.YEAR)), 4);
    c.gridx = 1;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 0);
    optionsPnl.add(fromYY, c);
    JLabel separatorF1 = new JLabel("-");
    c.gridx = 2;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 0, 5, 0);
    optionsPnl.add(separatorF1, c);
    fromMM = new JTextField(Integer.toString(calendar.get(Calendar.MONTH) + 1), 2);
    c.gridx = 3;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(fromMM, c);
    JLabel separatorF2 = new JLabel("-");
    c.gridx = 4;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(separatorF2, c);
    fromDD = new JTextField(Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)), 2);
    c.gridx = 5;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(fromDD, c);
    JLabel tlbl = new JLabel("T");
    c.gridx = 6;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(tlbl, c);
    fromHr = new JTextField(Integer.toString(calendar.get(Calendar.HOUR_OF_DAY)), 2);
    c.gridx = 7;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(fromHr, c);
    JLabel comaF1Lbl = new JLabel(":");
    c.gridx = 8;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(comaF1Lbl, c);
    fromMin = new JTextField(Integer.toString(calendar.get(Calendar.MINUTE)), 2);
    c.gridx = 9;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(fromMin, c);
    JLabel comaF2Lbl = new JLabel(":");
    c.gridx = 10;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(comaF2Lbl, c);
    fromSec = new JTextField(Integer.toString(calendar.get(Calendar.SECOND)), 2);
    c.gridx = 11;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.gridwidth = GridBagConstraints.REMAINDER;
    optionsPnl.add(fromSec, c);

    toYY = new JTextField(Integer.toString(calendar.get(Calendar.YEAR)), 4);
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 5, 5, 0);
    optionsPnl.add(toYY, c);
    JLabel separatorTo1 = new JLabel("-");
    c.gridx = 2;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.insets = new Insets(5, 0, 5, 0);
    optionsPnl.add(separatorTo1, c);
    toMM = new JTextField(Integer.toString(calendar.get(Calendar.MONTH) + 1), 2);
    c.gridx = 3;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(toMM, c);
    JLabel separatorTo2 = new JLabel("-");
    c.gridx = 4;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(separatorTo2, c);
    toDD = new JTextField(Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)), 2);
    c.gridx = 5;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(toDD, c);
    JLabel t2lbl = new JLabel("T");
    c.gridx = 6;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(t2lbl, c);
    toHr = new JTextField(Integer.toString(calendar.get(Calendar.HOUR_OF_DAY)), 2);
    c.gridx = 7;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(toHr, c);
    JLabel comaTo1Lbl = new JLabel(":");
    c.gridx = 8;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(comaTo1Lbl, c);
    toMin = new JTextField(Integer.toString(calendar.get(Calendar.MINUTE)), 2);
    c.gridx = 9;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(toMin, c);
    JLabel comaTo2Lbl = new JLabel(":");
    c.gridx = 10;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    optionsPnl.add(comaTo2Lbl, c);
    toSec = new JTextField(Integer.toString(calendar.get(Calendar.SECOND)), 2);
    c.gridx = 11;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LAST_LINE_START;
    c.gridwidth = GridBagConstraints.REMAINDER;
    optionsPnl.add(toSec, c);

    rowLimit = new JTextField("10000", 20);
    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(10, 5, 5, 5);
    optionsPnl.add(rowLimit, c);
    routineName = new JTextField("*", 20);
    c.gridx = 1;
    c.gridy = 3;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(routineName, c);
    procName = new JTextField("*", 20);
    c.gridx = 1;
    c.gridy = 4;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(procName, c);
    sourceName = new JTextField("*", 20);
    c.gridx = 1;
    c.gridy = 5;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(sourceName, c);
    minLogLevelCB = setupTypeCB(minLogLevelCB);
    minLogLevelCB.setSelectedIndex(LogTypeHelper.INFO.ordinal());
    c.gridx = 1;
    c.gridy = 6;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(5, 5, 5, 5);
    optionsPnl.add(minLogLevelCB, c);
    maxLogLevelCB = setupTypeCB(maxLogLevelCB);
    maxLogLevelCB.setSelectedIndex(LogTypeHelper.EMERGENCY.ordinal());
    c.gridx = 1;
    c.gridy = 7;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(5, 5, 10, 5);
    optionsPnl.add(maxLogLevelCB, c);

    // Add the OK, CANCEL buttons
    JPanel bottomPanel = new JPanel(new BorderLayout());
    JPanel btnPnl = new JPanel();
    btnPnl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    BoxLayout boxLayout = new BoxLayout(btnPnl, BoxLayout.LINE_AXIS);
    btnPnl.setLayout(boxLayout);
    btnPnl.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    submitBtn = new JButton("Submit");
    submitBtn.addActionListener(this);
    submitBtn.setEnabled(archive.getDBStatus() == DBState.DATABASE_OK);
    doneBtn = new JButton("Cancel");
    doneBtn.addActionListener(this);
    btnPnl.add(submitBtn, BorderLayout.WEST);
    btnPnl.add(Box.createRigidArea(new Dimension(10, 0)));
    btnPnl.add(doneBtn, BorderLayout.EAST);
    btnPnl.add(Box.createRigidArea(new Dimension(10, 0)));

    // Set the border and a smaller font for the label
    statusLbl.setBorder(BorderFactory.createLoweredBevelBorder());
    Font fnt = statusLbl.getFont();
    Font newFont = fnt.deriveFont(fnt.getSize() * 2 / 3);
    statusLbl.setFont(newFont);
    bottomPanel.add(btnPnl, BorderLayout.EAST);
    bottomPanel.add(statusLbl, BorderLayout.CENTER);
    // Add the subpanels
    mainPnl.add(guiSwitches, BorderLayout.NORTH);
    mainPnl.add(optionsPnl, BorderLayout.CENTER);
    mainPnl.add(bottomPanel, BorderLayout.SOUTH);
  }
Exemplo n.º 4
0
        @Override
        public void actionPerformed(ActionEvent evt) {
          final JDialog authPanel =
              new JDialog(getWindow(SubtitlePanel.this), ModalityType.APPLICATION_MODAL);
          authPanel.setTitle("Login");
          authPanel.setLocation(getOffsetLocation(authPanel.getOwner()));

          JPanel osdbGroup = new JPanel(new MigLayout("fill, insets panel"));
          osdbGroup.setBorder(new TitledBorder("OpenSubtitles"));
          osdbGroup.add(new JLabel("Username:"******"gap rel");
          final JTextField osdbUser = new JTextField(12);
          osdbGroup.add(osdbUser, "growx, wrap rel");

          osdbGroup.add(new JLabel("Password:"******"gap rel");
          final JPasswordField osdbPass = new JPasswordField(12);
          osdbGroup.add(osdbPass, "growx, wrap unrel");

          // restore values
          String[] osdbAuth = WebServices.getLogin(WebServices.LOGIN_OPENSUBTITLES);
          osdbUser.setText(osdbAuth[0]);
          // osdbPass.setText(osdbAuth[1]); // password is stored as MD5 hash so we can't restore it

          if (osdbUser.getText().isEmpty()) {
            osdbGroup.add(
                new LinkButton(
                    "Register Account",
                    "Register to increase your download quota",
                    WebServices.OpenSubtitles.getIcon(),
                    URI.create("http://www.opensubtitles.org/en/newuser")),
                "spanx 2, tag left");
          } else {
            osdbGroup.add(
                new LinkButton(
                    "Upgrade Account",
                    "Upgrade to increase your download quota",
                    WebServices.OpenSubtitles.getIcon(),
                    URI.create("http://www.opensubtitles.org/en/support")),
                "spanx 2, tag left");
          }

          JRootPane container = authPanel.getRootPane();
          container.setLayout(new MigLayout("fill, insets dialog"));
          container.removeAll();

          container.add(osdbGroup, "growx, wrap");

          Action ok =
              new AbstractAction("OK", ResourceManager.getIcon("dialog.continue")) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                  authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                  boolean approved = true;

                  try {
                    if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
                      final OpenSubtitlesClient osdb =
                          new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
                      osdb.setUser(osdbUser.getText(), md5(new String(osdbPass.getPassword())));
                      osdb.login();

                      // do some status checks in background (since OpenSubtitles can be really
                      // really slow)
                      WebServices.requestThreadPool.submit(
                          () -> {
                            try {
                              // check download quota for the current user
                              Map<?, ?> limits =
                                  (Map<?, ?>) osdb.getServerInfo().get("download_limits");
                              log.log(
                                  Level.INFO,
                                  String.format(
                                      "Your daily download quota is at %s of %s.",
                                      limits.get("client_24h_download_count"),
                                      limits.get("client_24h_download_limit")));

                              // logout from test session
                              osdb.logout();
                            } catch (Exception e) {
                              debug.warning(e.getMessage());
                            }
                          });
                    } else if (osdbUser.getText().isEmpty()) {
                      WebServices.setLogin(
                          WebServices.LOGIN_OPENSUBTITLES, null, null); // delete login details
                    }
                  } catch (Exception e) {
                    log.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
                    approved = false;
                  }

                  authPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                  if (approved) {
                    WebServices.setLogin(
                        WebServices.LOGIN_OPENSUBTITLES,
                        osdbUser.getText(),
                        new String(osdbPass.getPassword()));
                    authPanel.setVisible(false);
                  }
                }
              };
          Action cancel =
              new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) {

                @Override
                public void actionPerformed(ActionEvent evt) {
                  authPanel.setVisible(false);
                }
              };
          container.add(new JButton(cancel), "tag cancel, split 2");
          container.add(new JButton(ok), "tag ok");

          authPanel.pack();
          authPanel.setVisible(true);
        }
Exemplo n.º 5
0
  /** Initializes the layout and the ribbon. */
  private void initRibbon() {
    this.setLayout(new RibbonFrameLayout());
    this.ribbon = new JRibbon(this);
    this.add(this.ribbon, BorderLayout.NORTH);

    // this.keyTipManager = new KeyTipManager(this);
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              private boolean prevAltModif = false;

              @Override
              public void eventDispatched(AWTEvent event) {
                Object src = event.getSource();
                if (src instanceof Component) {
                  Component c = (Component) src;
                  if ((c == JRibbonFrame.this)
                      || (SwingUtilities.getWindowAncestor(c) == JRibbonFrame.this)) {
                    if (event instanceof KeyEvent) {
                      KeyEvent keyEvent = (KeyEvent) event;
                      // System.out.println(keyEvent.getID() + ":"
                      // + keyEvent.getKeyCode());
                      switch (keyEvent.getID()) {
                        case KeyEvent.KEY_PRESSED:
                          // if (keyEvent.getKeyCode() ==
                          // KeyEvent.VK_ESCAPE) {
                          // keyTipManager.showPreviousChain();
                          // }

                          break;
                        case KeyEvent.KEY_RELEASED:
                          boolean wasAltModif = prevAltModif;
                          prevAltModif = keyEvent.getModifiersEx() == InputEvent.ALT_DOWN_MASK;
                          if (wasAltModif && keyEvent.getKeyCode() == KeyEvent.VK_ALT) break;
                          char keyChar = keyEvent.getKeyChar();
                          if (Character.isLetter(keyChar) || Character.isDigit(keyChar)) {
                            // System.out.println("Will handle key press "
                            // + keyChar);
                            KeyTipManager.defaultManager().handleKeyPress(keyChar);
                          }
                          if ((keyEvent.getKeyCode() == KeyEvent.VK_ALT)
                              || (keyEvent.getKeyCode() == KeyEvent.VK_F10)) {
                            if (keyEvent.getModifiers() != 0 || keyEvent.getModifiersEx() != 0)
                              break;
                            boolean hadPopups =
                                !PopupPanelManager.defaultManager().getShownPath().isEmpty();
                            PopupPanelManager.defaultManager().hidePopups(null);
                            if (hadPopups || KeyTipManager.defaultManager().isShowingKeyTips()) {
                              KeyTipManager.defaultManager().hideAllKeyTips();
                            } else {
                              KeyTipManager.defaultManager().showRootKeyTipChain(JRibbonFrame.this);
                            }
                          }
                          if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) {
                            // System.out.println("In KTM");
                            KeyTipManager.defaultManager().showPreviousChain();
                          }
                          break;
                      }
                    }
                    if (event instanceof MouseEvent) {
                      MouseEvent mouseEvent = (MouseEvent) event;
                      switch (mouseEvent.getID()) {
                        case MouseEvent.MOUSE_CLICKED:
                        case MouseEvent.MOUSE_DRAGGED:
                        case MouseEvent.MOUSE_PRESSED:
                        case MouseEvent.MOUSE_RELEASED:
                          KeyTipManager.defaultManager().hideAllKeyTips();
                      }
                    }
                  }
                }
              }
            },
            AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);

    final KeyTipLayer keyTipLayer = new KeyTipLayer();
    JRootPane rootPane = this.getRootPane();
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    final LayoutManager currLM = rootPane.getLayout();
    rootPane.setLayout(
        new LayoutManager() {
          @Override
          public void addLayoutComponent(String name, Component comp) {
            currLM.addLayoutComponent(name, comp);
          }

          @Override
          public void layoutContainer(Container parent) {
            currLM.layoutContainer(parent);
            JRibbonFrame ribbonFrame = JRibbonFrame.this;
            if (ribbonFrame.getRootPane().getWindowDecorationStyle() != JRootPane.NONE)
              keyTipLayer.setBounds(ribbonFrame.getRootPane().getBounds());
            else keyTipLayer.setBounds(ribbonFrame.getRootPane().getContentPane().getBounds());
          }

          @Override
          public Dimension minimumLayoutSize(Container parent) {
            return currLM.minimumLayoutSize(parent);
          }

          @Override
          public Dimension preferredLayoutSize(Container parent) {
            return currLM.preferredLayoutSize(parent);
          }

          @Override
          public void removeLayoutComponent(Component comp) {
            currLM.removeLayoutComponent(comp);
          }
        });
    // layeredPane.setLayout(new OverlayLayout(layeredPane));
    layeredPane.add(keyTipLayer, (Integer) (JLayeredPane.DEFAULT_LAYER + 60));

    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowDeactivated(WindowEvent e) {
            // hide all key tips on window deactivation
            KeyTipManager keyTipManager = KeyTipManager.defaultManager();
            if (keyTipManager.isShowingKeyTips()) {
              keyTipManager.hideAllKeyTips();
            }
          }
        });

    KeyTipManager.defaultManager()
        .addKeyTipListener(
            new KeyTipManager.KeyTipListener() {
              @Override
              public void keyTipsHidden(KeyTipEvent event) {
                if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(false);
              }

              @Override
              public void keyTipsShown(KeyTipEvent event) {
                if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(true);
              }
            });

    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    super.setIconImages(Arrays.asList(FlamingoUtilities.getBlankImage(16, 16)));
  }