コード例 #1
0
    public Dimension preferredLayoutSize(Container parent) {
      JToolBar tb = (JToolBar) parent;
      Insets insets = tb.getInsets();
      Dimension dim = new Dimension();
      SeaGlassContext context = getContext(tb);

      if (tb.getOrientation() == JToolBar.HORIZONTAL) {
        dim.width = tb.isFloatable() ? SeaGlassIcon.getIconWidth(handleIcon, context) : 0;
        Dimension compDim;
        for (int i = 0; i < tb.getComponentCount(); i++) {
          Component component = tb.getComponent(i);
          if (component.isVisible()) {
            compDim = component.getPreferredSize();
            dim.width += compDim.width;
            dim.height = Math.max(dim.height, compDim.height);
          }
        }
      } else {
        dim.height = tb.isFloatable() ? SeaGlassIcon.getIconHeight(handleIcon, context) : 0;
        Dimension compDim;
        for (int i = 0; i < tb.getComponentCount(); i++) {
          Component component = tb.getComponent(i);
          if (component.isVisible()) {
            compDim = component.getPreferredSize();
            dim.width = Math.max(dim.width, compDim.width);
            dim.height += compDim.height;
          }
        }
      }
      dim.width += insets.left + insets.right;
      dim.height += insets.top + insets.bottom;

      context.dispose();
      return dim;
    }
コード例 #2
0
ファイル: MapFrame.java プロジェクト: sbrunner/josm
  /**
   * Called as some kind of destructor when the last layer has been removed. Delegates the call to
   * all Destroyables within this component (e.g. MapModes)
   */
  public void destroy() {
    MapView.removeLayerChangeListener(this);
    dialogsPanel.destroy();
    for (int i = 0; i < toolBarActions.getComponentCount(); ++i) {
      if (toolBarActions.getComponent(i) instanceof Destroyable) {
        ((Destroyable) toolBarActions.getComponent(i)).destroy();
      }
    }
    for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) {
      if (toolBarToggle.getComponent(i) instanceof Destroyable) {
        ((Destroyable) toolBarToggle.getComponent(i)).destroy();
      }
    }

    // MapFrame gets destroyed when the last layer is removed, but the status line background
    // thread that collects the information doesn't get destroyed automatically.
    if (statusLine.thread != null) {
      try {
        statusLine.thread.interrupt();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    mapView.destroy();
  }
コード例 #3
0
  private JToolBar removeUnnecessarySeparators(JToolBar toolBar) {
    Component component;
    int previousDeleted = -1;
    int nbComponents = toolBar.getComponentCount();
    for (int i = 0; i < nbComponents; ) {
      component = toolBar.getComponent(i);
      if (toolBar.getComponent(i).getClass() == JSeparator.class) {
        if (i > previousDeleted) {
          toolBar.remove(component);
          nbComponents--;
        } else {
          i++;
        }
      } else {
        previousDeleted = ++i;
      }
    }

    if (nbComponents > 0) {
      component = toolBar.getComponent(toolBar.getComponentCount() - 1);
      if (component != null && component.getClass() == JSeparator.class) {
        toolBar.remove(component);
      }
    }
    return toolBar;
  }
コード例 #4
0
ファイル: MapFrame.java プロジェクト: rheinz/josm
  /**
   * Called as some kind of destructor when the last layer has been removed. Delegates the call to
   * all Destroyables within this component (e.g. MapModes)
   */
  @Override
  public void destroy() {
    MapView.removeLayerChangeListener(this);
    dialogsPanel.destroy();
    Main.pref.removePreferenceChangeListener(sidetoolbarPreferencesChangedListener);
    for (int i = 0; i < toolBarActions.getComponentCount(); ++i) {
      if (toolBarActions.getComponent(i) instanceof Destroyable) {
        ((Destroyable) toolBarActions.getComponent(i)).destroy();
      }
    }
    for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) {
      if (toolBarToggle.getComponent(i) instanceof Destroyable) {
        ((Destroyable) toolBarToggle.getComponent(i)).destroy();
      }
    }

    statusLine.destroy();
    mapView.destroy();
  }
コード例 #5
0
ファイル: WorkingView.java プロジェクト: BackupTheBerlios/tbe
  /** Installs default Tools (Cursor, Add and Remove Point, Rotate, TextBox) into the toolbar */
  private void initDefaultTools() {
    cursorTool = currentTool = ToolFactory.getCursorTool();
    this.installToolInToolBar(toolbar, currentTool);
    toolbar.addSeparator();
    installAddRemovePointButtons();
    cursorButton = currentButton = (JButton) toolbar.getComponent(0);

    toolbar.addSeparator();
    this.installToolInToolBar(toolbar, ToolFactory.getTextBoxTool());
    toolbar.addSeparator();

    this.installRotateButton();
    toolbar.addSeparator();
  }
コード例 #6
0
  /** This method uninstalls listeners installed by the UI. */
  protected void uninstallListeners() {
    if (toolBarFocusListener != null) {
      int count = toolBar.getComponentCount();
      for (int i = 0; i < count; i++)
        toolBar.getComponent(i).removeFocusListener(toolBarFocusListener);
      toolBarFocusListener = null;
    }

    floatFrame.removeWindowListener(windowListener);
    windowListener = null;

    toolBar.removeContainerListener(toolBarContListener);
    toolBarContListener = null;

    toolBar.removeMouseMotionListener(dockingListener);
    toolBar.removeMouseListener(dockingListener);
    dockingListener = null;
  }
コード例 #7
0
  /** This method installs listeners for the JToolBar. */
  protected void installListeners() {
    dockingListener = createDockingListener();
    toolBar.addMouseListener(dockingListener);
    toolBar.addMouseMotionListener(dockingListener);

    propertyListener = createPropertyListener();
    toolBar.addPropertyChangeListener(propertyListener);

    toolBarContListener = createToolBarContListener();
    toolBar.addContainerListener(toolBarContListener);

    windowListener = createFrameListener();
    floatFrame.addWindowListener(windowListener);

    toolBarFocusListener = createToolBarFocusListener();
    if (toolBarFocusListener != null) {
      int count = toolBar.getComponentCount();
      for (int i = 0; i < count; i++)
        toolBar.getComponent(i).addFocusListener(toolBarFocusListener);
    }
  }
コード例 #8
0
    public void layoutContainer(Container parent) {
      JToolBar tb = (JToolBar) parent;
      Insets insets = tb.getInsets();
      boolean ltr = tb.getComponentOrientation().isLeftToRight();
      SeaGlassContext context = getContext(tb);

      Component c;
      Dimension d;

      // JToolBar by default uses a somewhat modified BoxLayout as
      // its layout manager. For compatibility reasons, we want to
      // support Box "glue" as a way to move things around on the
      // toolbar. "glue" is represented in BoxLayout as a Box.Filler
      // with a minimum and preferred size of (0,0).
      // So what we do here is find the number of such glue fillers
      // and figure out how much space should be allocated to them.
      int glueCount = 0;
      for (int i = 0; i < tb.getComponentCount(); i++) {
        if (isGlue(tb.getComponent(i))) glueCount++;
      }

      if (tb.getOrientation() == JToolBar.HORIZONTAL) {
        int handleWidth = tb.isFloatable() ? SeaGlassIcon.getIconWidth(handleIcon, context) : 0;

        // Note: contentRect does not take insets into account
        // since it is used for determining the bounds that are
        // passed to paintToolBarContentBackground().
        contentRect.x = ltr ? handleWidth : 0;
        contentRect.y = 0;
        contentRect.width = tb.getWidth() - handleWidth;
        contentRect.height = tb.getHeight();

        // However, we do take the insets into account here for
        // the purposes of laying out the toolbar child components.
        int x = ltr ? handleWidth + insets.left : tb.getWidth() - handleWidth - insets.right;
        int baseY = insets.top;
        int baseH = tb.getHeight() - insets.top - insets.bottom;

        // we need to get the minimum width for laying things out
        // so that we can calculate how much empty space needs to
        // be distributed among the "glue", if any
        int extraSpacePerGlue = 0;
        if (glueCount > 0) {
          int minWidth = minimumLayoutSize(parent).width;
          extraSpacePerGlue = (tb.getWidth() - minWidth) / glueCount;
          if (extraSpacePerGlue < 0) extraSpacePerGlue = 0;
        }

        for (int i = 0; i < tb.getComponentCount(); i++) {
          c = tb.getComponent(i);
          if (c.isVisible()) {
            d = c.getPreferredSize();
            int y, h;
            if (d.height >= baseH || c instanceof JSeparator) {
              // Fill available height
              y = baseY;
              h = baseH;
            } else {
              // Center component vertically in the available
              // space
              y = baseY + (baseH / 2) - (d.height / 2);
              h = d.height;
            }
            // if the component is a "glue" component then add to
            // its
            // width the extraSpacePerGlue it is due
            if (isGlue(c)) d.width += extraSpacePerGlue;
            c.setBounds(ltr ? x : x - d.width, y, d.width, h);
            x = ltr ? x + d.width : x - d.width;
          }
        }
      } else {
        int handleHeight = tb.isFloatable() ? SeaGlassIcon.getIconHeight(handleIcon, context) : 0;

        // See notes above regarding the use of insets
        contentRect.x = 0;
        contentRect.y = handleHeight;
        contentRect.width = tb.getWidth();
        contentRect.height = tb.getHeight() - handleHeight;

        int baseX = insets.left;
        int baseW = tb.getWidth() - insets.left - insets.right;
        int y = handleHeight + insets.top;

        // we need to get the minimum height for laying things out
        // so that we can calculate how much empty space needs to
        // be distributed among the "glue", if any
        int extraSpacePerGlue = 0;
        if (glueCount > 0) {
          int minHeight = minimumLayoutSize(parent).height;
          extraSpacePerGlue = (tb.getHeight() - minHeight) / glueCount;
          if (extraSpacePerGlue < 0) extraSpacePerGlue = 0;
        }

        for (int i = 0; i < tb.getComponentCount(); i++) {
          c = tb.getComponent(i);
          if (c.isVisible()) {
            d = c.getPreferredSize();
            int x, w;
            if (d.width >= baseW || c instanceof JSeparator) {
              // Fill available width
              x = baseX;
              w = baseW;
            } else {
              // Center component horizontally in the available
              // space
              x = baseX + (baseW / 2) - (d.width / 2);
              w = d.width;
            }
            // if the component is a "glue" component then add to
            // its
            // height the extraSpacePerGlue it is due
            if (isGlue(c)) d.height += extraSpacePerGlue;
            c.setBounds(x, y, w, d.height);
            y += d.height;
          }
        }
      }
      context.dispose();
    }
コード例 #9
0
  /**
   * Create a toolbar containing the given tools (if any).
   *
   * @param template Conta
   */
  protected void changeToolBar(JComponent[] template, IControlCenterPlugin selplugin) {
    // Setup the tool bar.
    if (toolbar == null) {
      toolbar = new JToolBar("Main Toolbar");
      getContentPane().add(BorderLayout.NORTH, toolbar);
      // Add standard entries (after gap).
      toolbar.add(Box.createGlue());
      toolcnt++;
      toolbar.addSeparator();
      toolcnt++;

      // ButtonGroup bg = new ButtonGroup();
      IControlCenterPlugin[] plugins = controlcenter.getPlugins();
      for (int i = 0; i < plugins.length; i++) {
        final IControlCenterPlugin plugin = plugins[i];
        // final JToggleButton button = new JToggleButton(new PluginAction(plugins[i]));
        final JButton button = new JButton(new PluginAction(plugins[i]));
        Icon ic = plugin.getToolIcon(selplugin.getName().equals(plugins[i].getName()));
        if (ic != null) button.setIcon(ic);
        else button.setText(plugins[i].getName());
        button.setText("A");
        button.putClientProperty("plugin", plugins[i]);
        button.setBorder(null);
        button.setText(null);
        button.setMinimumSize(BUTTON_DIM);
        button.setHorizontalAlignment(SwingConstants.CENTER);
        button.setVerticalAlignment(SwingConstants.CENTER);
        button.setToolTipText(plugins[i].getName());
        button
            .getModel()
            .addItemListener(
                new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                    // System.out.println(plugin.getName()+" :"+button.isSelected());
                    button.setIcon(plugin.getToolIcon(button.isSelected()));
                  }
                });
        //	            if(plugins[i].getHelpID()!=null)
        //	            	SHelp.setupHelp(button, plugins[i].getHelpID());

        // bg.add(button);
        toolbar.add(button);
        toolcnt++;
      }
      toolbar.addSeparator();
      toolcnt++;
      toolbar.add(new JadexLogoButton(toolbar));
      toolcnt++;
    } else {
      while (toolbar.getComponentCount() > toolcnt) {
        //				Component	comp	= toolbar.getComponent(0);
        toolbar.remove(0);
        // if(lasttoolbar!=null)
        //	lasttoolbar.add(comp);
      }
    }

    for (int i = 0; template != null && i < template.length; i++) toolbar.add(template[i], i);
    // lasttoolbar	= template;

    // Select plugins
    for (int i = 0; i < toolbar.getComponentCount(); i++) {
      JComponent comp = (JComponent) toolbar.getComponent(i);
      if (comp.getClientProperty("plugin") != null) {
        IControlCenterPlugin pl = (IControlCenterPlugin) comp.getClientProperty("plugin");
        ((JButton) comp).setIcon(pl.getToolIcon(pl.equals(selplugin)));
        // ((JToggleButton)comp).setSelected(pluginname.equals(comp.getClientProperty("pluginname")));
      }
    }

    toolbar.validate();
    toolbar.repaint();

    // If toolbar has been dropped out -> pack the window (hack???).
    Container root = toolbar;
    while (root.getParent() != null && !(root instanceof Window)) root = root.getParent();
    if (root != null && !(root instanceof JFrame)) {
      ((Window) root).pack();
    }
  }
コード例 #10
0
ファイル: MapFrame.java プロジェクト: rheinz/josm
 public Action getDefaultButtonAction() {
   return ((AbstractButton) toolBarActions.getComponent(0)).getAction();
 }
コード例 #11
0
ファイル: MapFrame.java プロジェクト: sbrunner/josm
  public MapFrame(JPanel contentPane) {
    setSize(400, 400);
    setLayout(new BorderLayout());

    mapView = new MapView(contentPane);

    new FileDrop(mapView);

    leftPanel = new JPanel();
    leftPanel.setLayout(new GridBagLayout());

    leftPanel.add(mapView, GBC.std().fill());

    // toolbar
    toolBarActions.setFloatable(false);
    addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));
    addMapMode(new IconToggleButton(new LassoModeAction(), true));
    addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this)));
    addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this)));
    addMapMode(new IconToggleButton(new DeleteAction(this), true));
    addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
    addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
    addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true));

    toolGroup.setSelected(((AbstractButton) toolBarActions.getComponent(0)).getModel(), true);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    dialogsPanel = new DialogsPanel(splitPane);
    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(dialogsPanel);

    /** All additional space goes to the mapView */
    splitPane.setResizeWeight(1.0);

    /** Some beautifications. */
    splitPane.setDividerSize(5);
    splitPane.setBorder(null);
    splitPane.setUI(
        new BasicSplitPaneUI() {
          @Override
          public BasicSplitPaneDivider createDefaultDivider() {
            return new BasicSplitPaneDivider(this) {
              @Override
              public void setBorder(Border b) {}
            };
          }
        });

    // JSplitPane supports F6 and F8 shortcuts by default, but we need them for Audio actions
    splitPane
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), new Object());
    splitPane
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), new Object());

    add(splitPane, BorderLayout.CENTER);

    dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS));
    dialogsPanel.setPreferredSize(
        new Dimension(Main.pref.getInteger("toggleDialogs.width", DEF_TOGGLE_DLG_WIDTH), 0));

    dialogsPanel.setMinimumSize(new Dimension(24, 0));
    mapView.setMinimumSize(new Dimension(10, 0));

    toolBarToggle.setFloatable(false);
    LayerListDialog.createInstance(this);
    addToggleDialog(LayerListDialog.getInstance());
    addToggleDialog(propertiesDialog = new PropertiesDialog(this));
    addToggleDialog(selectionListDialog = new SelectionListDialog());
    addToggleDialog(relationListDialog = new RelationListDialog());
    addToggleDialog(new CommandStackDialog(this));
    addToggleDialog(new UserListDialog());
    addToggleDialog(new HistoryDialog(), true);
    addToggleDialog(conflictDialog = new ConflictDialog());
    addToggleDialog(validatorDialog = new ValidatorDialog());
    addToggleDialog(filterDialog = new FilterDialog());
    addToggleDialog(new ChangesetDialog(this), true);
    addToggleDialog(new MapPaintDialog());

    // status line below the map
    statusLine = new MapStatus(this);
    MapView.addLayerChangeListener(this);
  }