Exemplo n.º 1
0
  /**
   * Standard constructor.
   *
   * @param type Type that you are going to be creating and editor for.
   * @param readOnly Set to true to create a read-only customizer.
   */
  public DynamicCustomizer(Class type, boolean readOnly) {
    super(new GridBagLayout());
    _readOnly = readOnly;
    _type = type;

    LabelFieldGBC gbc = new LabelFieldGBC();
    try {
      BeanInfo info = Introspector.getBeanInfo(type);
      // Set up pretty display stuff.
      setBorder(BorderFactory.createTitledBorder(info.getBeanDescriptor().getDisplayName()));
      setToolTipText(info.getBeanDescriptor().getShortDescription());

      // Get the properties and sort them.
      PropertyDescriptor[] props = info.getPropertyDescriptors();
      Arrays.sort(props, new PropertyComparator());
      for (int i = 0; i < props.length; i++) {
        // Ignore the "class" property, if it is provided.
        if (props[i].getName().equals("class")) continue;
        // Create a label for the field.
        JLabel label = new JLabel(props[i].getDisplayName() + ":");

        // Lookup the editor.
        PropertyEditor editor = getEditorForProperty(props[i]);

        // Add a listener to the editor so we know when to update
        // the bean's fields.
        editor.addPropertyChangeListener(_eListener);

        // XXX What we need to do right here is provide a component
        // that makes use of the "paintable" capability of the editor.
        Component comp = editor.getCustomEditor();
        if (comp == null) {
          comp = new JLabel("<No editor available.>");
          ((JLabel) comp).setBorder(BorderFactory.createEtchedBorder());
        }

        // See if it is a read-only property. If so, then just
        // display it.
        if (_readOnly || props[i].getWriteMethod() == null) {
          comp.setEnabled(false);
        }

        // Setup the accellerator key.
        label.setLabelFor(comp);
        label.setDisplayedMnemonic(label.getText().charAt(0));

        // Set the tool tip text, if any.
        String tip = props[i].getShortDescription();
        if (tip != null) {
          label.setToolTipText(tip);
          if (comp instanceof JComponent) {
            ((JComponent) comp).setToolTipText(tip);
          }
        }

        // Add the label and fields.
        add(label, gbc.forLabel());
        add(comp, gbc.forField());

        // Set the mappings between editor and property, etc. for
        // quick lookup later.
        _prop2Editor.put(props[i], editor);
        _editor2Prop.put(editor, props[i]);
      }
      // Filler...
      add(new JLabel(), gbc.forLastLabel());

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public Viewport(CConn cc_) {
    cc = cc_;
    updateTitle();
    setFocusable(false);
    setFocusTraversalKeysEnabled(false);
    setIconImage(VncViewer.frameImage);
    UIManager.getDefaults()
        .put("ScrollPane.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {}));
    sp = new JScrollPane();
    sp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    sp.getViewport().setBackground(Color.BLACK);
    InputMap im = sp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    int ctrlAltShiftMask = Event.SHIFT_MASK | Event.CTRL_MASK | Event.ALT_MASK;
    if (im != null) {
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ctrlAltShiftMask), "unitScrollUp");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ctrlAltShiftMask), "unitScrollDown");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ctrlAltShiftMask), "unitScrollLeft");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ctrlAltShiftMask), "unitScrollRight");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, ctrlAltShiftMask), "scrollUp");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, ctrlAltShiftMask), "scrollDown");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, ctrlAltShiftMask), "scrollLeft");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, ctrlAltShiftMask), "scrollRight");
    }
    tb = new Toolbar(cc);
    add(tb, BorderLayout.PAGE_START);
    getContentPane().add(sp);
    if (VncViewer.os.startsWith("mac os x")) {
      macMenu = new MacMenuBar(cc);
      setJMenuBar(macMenu);
      if (VncViewer.getBooleanProperty("turbovnc.lionfs", true)) enableLionFS();
    }
    // NOTE: If Lion FS mode is enabled, then the viewport is only created once
    // as a non-full-screen viewport, so we tell showToolbar() to ignore the
    // full-screen state.
    showToolbar(cc.showToolbar, canDoLionFS);

    addWindowFocusListener(
        new WindowAdapter() {
          public void windowGainedFocus(WindowEvent e) {
            if (sp.getViewport().getView() != null)
              sp.getViewport().getView().requestFocusInWindow();
            if (isVisible() && keyboardTempUngrabbed) {
              vlog.info("Keyboard focus regained. Re-grabbing keyboard.");
              grabKeyboardHelper(true);
              keyboardTempUngrabbed = false;
            }
          }

          public void windowLostFocus(WindowEvent e) {
            if (cc.keyboardGrabbed && isVisible()) {
              vlog.info("Keyboard focus lost. Temporarily ungrabbing keyboard.");
              grabKeyboardHelper(false);
              keyboardTempUngrabbed = true;
            }
          }
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            cc.close();
          }
        });

    addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            if (cc.opts.scalingFactor == Options.SCALE_AUTO
                || cc.opts.scalingFactor == Options.SCALE_FIXEDRATIO) {
              if ((sp.getSize().width != cc.desktop.scaledWidth)
                  || (sp.getSize().height != cc.desktop.scaledHeight)) {
                cc.desktop.setScaledSize();
                sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
                sp.validate();
                if (getExtendedState() != JFrame.MAXIMIZED_BOTH && !cc.opts.fullScreen) {
                  sp.setSize(new Dimension(cc.desktop.scaledWidth, cc.desktop.scaledHeight));
                  int w = cc.desktop.scaledWidth + VncViewer.insets.left + VncViewer.insets.right;
                  int h = cc.desktop.scaledHeight + VncViewer.insets.top + VncViewer.insets.bottom;
                  if (tb.isVisible()) h += tb.getHeight();
                  if (cc.opts.scalingFactor == Options.SCALE_FIXEDRATIO) setSize(w, h);
                }
              }
            } else if (cc.opts.desktopSize.mode == Options.SIZE_AUTO
                && !cc.firstUpdate
                && !cc.pendingServerResize) {
              Dimension availableSize = cc.viewport.getAvailableSize();
              if (availableSize.width >= 1
                  && availableSize.height >= 1
                  && (availableSize.width != cc.desktop.scaledWidth
                      || availableSize.height != cc.desktop.scaledHeight)) {
                sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                sp.validate();
                if (timer != null) timer.stop();
                ActionListener actionListener =
                    new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                        Dimension availableSize = cc.viewport.getAvailableSize();
                        if (availableSize.width < 1 || availableSize.height < 1)
                          throw new ErrorException("Unexpected zero-size component");
                        cc.sendDesktopSize(availableSize.width, availableSize.height, true);
                      }
                    };
                timer = new Timer(500, actionListener);
                timer.setRepeats(false);
                timer.start();
              }
            } else {
              sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
              sp.validate();
            }
            if (cc.desktop.cursor != null) {
              Cursor cursor = cc.desktop.cursor;
              if (cursor.hotspot != null)
                // hotspot will be null until the first cursor update is received
                // from the server.
                cc.setCursor(
                    cursor.width(),
                    cursor.height(),
                    cursor.hotspot,
                    (int[]) cursor.data,
                    cursor.mask);
            }
            if (((sp.getSize().width > cc.desktop.scaledWidth)
                    || (sp.getSize().height > cc.desktop.scaledHeight))
                && cc.opts.desktopSize.mode != Options.SIZE_AUTO) {
              int w = sp.getSize().width - adjustWidth;
              int h = sp.getSize().height - adjustHeight;
              dx =
                  (w <= cc.desktop.scaledWidth)
                      ? 0
                      : (int) Math.floor((w - cc.desktop.scaledWidth) / 2);
              dy =
                  (h <= cc.desktop.scaledHeight)
                      ? 0
                      : (int) Math.floor((h - cc.desktop.scaledHeight) / 2);
            } else {
              dx = dy = 0;
            }
            repaint();
          }
        });
  }
Exemplo n.º 3
0
  public SketchProperties(Editor e, Sketch s) {
    super();

    editor = e;
    sketch = s;

    fields = new HashMap<String, JComponent>();

    this.setPreferredSize(new Dimension(500, 400));
    this.setMinimumSize(new Dimension(500, 400));
    this.setMaximumSize(new Dimension(500, 400));
    this.setSize(new Dimension(500, 400));
    Point eLoc = editor.getLocation();
    int x = eLoc.x;
    int y = eLoc.y;

    Dimension eSize = editor.getSize();
    int w = eSize.width;
    int h = eSize.height;

    int cx = x + (w / 2);
    int cy = y + (h / 2);

    this.setLocation(new Point(cx - 250, cy - 200));
    this.setModal(true);

    outer = new JPanel(new BorderLayout());
    outer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    this.add(outer);

    win = new JPanel();
    win.setLayout(new BorderLayout());
    outer.add(win, BorderLayout.CENTER);

    buttonBar = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    saveButton = new JButton("OK");
    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            save();
            SketchProperties.this.dispose();
          }
        });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            SketchProperties.this.dispose();
          }
        });

    buttonBar.add(saveButton);
    buttonBar.add(cancelButton);

    win.add(buttonBar, BorderLayout.SOUTH);

    tabs = new JTabbedPane();

    overviewPane = new JPanel();
    overviewPane.setLayout(new BoxLayout(overviewPane, BoxLayout.PAGE_AXIS));
    overviewPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    addTextField(overviewPane, "author", "Sketch author:");
    addTextArea(overviewPane, "summary", "Summary:");
    addTextArea(overviewPane, "license", "Copyright / License:");
    tabs.add("Overview", overviewPane);

    objectsPane = new JPanel();
    objectsPane.setLayout(new BoxLayout(objectsPane, BoxLayout.PAGE_AXIS));
    objectsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    addTextField(objectsPane, "board", "Board:");
    addTextField(objectsPane, "core", "Core:");
    addTextField(objectsPane, "compiler", "Compiler:");
    addTextField(objectsPane, "port", "Serial port:");
    addTextField(objectsPane, "programmer", "Programmer:");
    JButton setDef = new JButton("Set to current IDE values");
    setDef.setMaximumSize(setDef.getPreferredSize());
    setDef.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setObjectValues();
          }
        });
    objectsPane.add(Box.createVerticalGlue());
    objectsPane.add(setDef);

    tabs.add("Objects", objectsPane);

    win.add(tabs, BorderLayout.CENTER);

    this.setTitle("Sketch Properties");

    this.pack();
    this.setVisible(true);
  }