예제 #1
0
 /** {@inheritDoc} */
 @Override
 protected void uninstallListeners(JComponent c) {
   super.uninstallListeners(c);
   c.removePropertyChangeListener(this);
   if (viewportViewFocusHandler != null) {
     JViewport viewport = ((JScrollPane) c).getViewport();
     viewport.removeContainerListener(viewportViewFocusHandler);
     if (viewport.getView() != null) {
       viewport.getView().removeFocusListener(viewportViewFocusHandler);
     }
     viewportViewFocusHandler = null;
   }
 }
예제 #2
0
    @Override
    public void layoutContainer(Container parent) {
      if (linkedViewPort == null) {
        super.layoutContainer(parent);
      } else {
        JViewport vp = (JViewport) parent;
        Component view = vp.getView();

        if (view != null) {
          Point p = linkedViewPort.getViewPosition();
          Dimension size = linkedViewPort.getViewSize();

          if (horizontalLink) {
            p.y = 0;
            size.height = vp.getExtentSize().height;
          } else {
            p.x = 0;
            size.width = vp.getExtentSize().width;
          }

          vp.setViewPosition(p);
          vp.setViewSize(size);
        }
      }
    }
예제 #3
0
  public DataModel getDataModel(TypeEl typeEl) {
    String type = new String();
    switch (typeEl) {
      case CD:
        type = "CD";
        break;
      case DVD:
        type = "DVD";
        break;
      case LIVRE:
        type = "Livre";
        break;
      case JEUX:
        type = "Jeux";
        break;
      case BD:
        type = "BD";
        break;
    }
    tabbedpane.setSelectedIndex(tabbedpane.indexOfTab(type));

    JScrollPane t = (JScrollPane) tabbedpane.getComponent(tabbedpane.indexOfTab(type));
    JViewport view = t.getViewport();
    JTable f = (JTable) view.getView();
    DataModel model = (DataModel) f.getModel();

    return model;
  }
예제 #4
0
  public void scrollToAttribute(Attribute a) {
    if (!a.getDescriptor().getConfig().equals(getConfig())) {
      logger.fine("Cannot scroll to attribute that isn't attached to this type of descriptor");
      return;
    }
    int rowIndex = getCurrentModel().getRowForDescriptor(a.getDescriptor());
    int colIndex = getCurrentModel().getColumnForAttribute(a);
    JScrollPane scrollPane = (JScrollPane) this.getComponent(0);
    JViewport viewport = (JViewport) scrollPane.getViewport();
    EnhancedTable table = (EnhancedTable) viewport.getView();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(rowIndex, colIndex, true);

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
  }
예제 #5
0
  private static void check() {
    try {
      JViewport vp = null;
      for (Component c : tabbedPane.getComponents()) {
        if (c instanceof JViewport) {
          vp = (JViewport) c;
          break;
        }
      }

      JComponent v = (JComponent) vp.getView();
      Rectangle vr = vp.getViewRect();
      Dimension vs = v.getSize();

      // The tab view must be scrolled to the end so that the last tab is visible
      if (vs.width != (vr.x + vr.width)) {
        throw new RuntimeException(
            "tabScroller.tabPanel view is positioned incorrectly: "
                + vs.width
                + " vs "
                + (vr.x + vr.width));
      }
    } catch (Exception e) {
      exception = e;
    }
  }
    private void updateColor(Component c) {
      if (!(c instanceof JScrollPane)) return;

      JViewport vp = ((JScrollPane) c).getViewport();
      if (vp == null) return;

      Component view = vp.getView();
      if (view == null) return;

      lineColor = view.getBackground();
    }
예제 #7
0
 /**
  * in Android server, AddHarHTMLMlet is NOT need to adapter size.
  *
  * @param scrollPane
  * @return
  */
 public static boolean isForAddHtml(final JScrollPane scrollPane) {
   if (scrollPane != null) {
     final JViewport jviewport = scrollPane.getViewport();
     if (jviewport != null) {
       final Component view = jviewport.getView();
       if (view != null && view instanceof SystemHTMLMlet) {
         return true;
       }
     }
   }
   return false;
 }
예제 #8
0
 @Override
 public Component getToolComponent() {
   JViewport viewPort = rootPane.getViewport();
   if (viewPort == null) {
     viewPort = new JViewport();
     rootPane.setViewport(viewPort);
   }
   if (viewPort.getView() != this) {
     viewPort.setView(this);
   }
   return rootPane;
 }
예제 #9
0
 private void configureEnclosingScrollPaneUI() {
   final Container p = getParent();
   if (p instanceof JViewport) {
     final Container gp = p.getParent();
     if (gp instanceof JScrollPane) {
       final JScrollPane scrollPane = (JScrollPane) gp;
       // Make certain we are the viewPort's view and not, for
       // example, the rowHeaderView of the scrollPane -
       // an implementor of fixed columns might do this.
       final JViewport viewport = scrollPane.getViewport();
       if (viewport == null || viewport.getView() != this) {
         return;
       }
       //  scrollPane.getViewport().setBackingStoreEnabled(true);
       //                Border border = scrollPane.getBorder ();
       //                if ( border == null || border instanceof UIResource )
       //                {
       //                    Border scrollPaneBorder = UIManager.getBorder (
       // "Table.scrollPaneBorder" );
       //                    if ( scrollPaneBorder != null )
       //                    {
       //                        scrollPane.setBorder ( scrollPaneBorder );
       //                    }
       //                }
       // add JScrollBar corner component if available from LAF and not already set by the user
       Component corner = scrollPane.getCorner(JScrollPane.UPPER_TRAILING_CORNER);
       if (corner == null || corner instanceof UIResource) {
         corner = null;
         final Object componentClass = UIManager.get("Table.scrollPaneCornerComponent");
         if (componentClass instanceof Class) {
           try {
             corner = (Component) ((Class) componentClass).newInstance();
           } catch (final Exception e) {
             // just ignore and don't set corner
           }
         }
         scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, corner);
       }
     }
   }
 }
  /**
   * Exports currently selected table to file
   *
   * @param tabbedPane - Currently loaded tabbedPane
   */
  public void exportCSVToFile(JTabbedPane tabbedPane) {

    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select where you'd like to save the CSV file");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String tabName = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
    chooser.setSelectedFile(new File(tabName.replaceAll("/", "-")));
    chooser.setAcceptAllFileFilterUsed(true);

    // If user chooses valid directory then saves CSV there
    if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
      String filepath = chooser.getSelectedFile() + ".csv";
      try {
        // Uses a file choo
        FileWriter writer = new FileWriter(filepath);
        JScrollPane currentScrollPane =
            (JScrollPane) tabbedPane.getComponentAt(tabbedPane.getSelectedIndex());
        JViewport viewport = currentScrollPane.getViewport();
        JTable currentTable = (JTable) viewport.getView();

        // Goes through column headings and adds to CSV file
        for (int i = 0; i < currentTable.getColumnCount(); i++) {
          writer.write(currentTable.getColumnName(i) + ",");
        }
        writer.write("\n");
        // Goes through rows and adds to CSV file
        for (int i = 0; i < currentTable.getRowCount(); i++) {
          for (int j = 0; j < currentTable.getColumnCount(); j++) {
            writer.write(currentTable.getValueAt(i, j).toString() + ",");
          }
          writer.write("\n");
        }
        writer.close();
        JOptionPane.showMessageDialog(null, "Table data successfully exported as CSV file");
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }