Ejemplo n.º 1
0
  /**
   * Load a file of a particular type. It's a pretty standard helper function, which uses DarwinCSV
   * and setCurrentCSV(...) to make file loading happen with messaging and whatnot. We can also
   * reset the display: just call loadFile(null).
   *
   * @param file The file to load.
   * @param type The type of file (see DarwinCSV's constants).
   */
  private void loadFile(File file, short type) {
    // If the file was reset, reset the display and keep going.
    if (file == null) {
      mainFrame.setTitle(basicTitle);
      setCurrentCSV(null);
      return;
    }

    // Load up a new DarwinCSV and set current CSV.
    try {
      setCurrentCSV(new DarwinCSV(file, type));

    } catch (IOException ex) {
      MessageBox.messageBox(
          mainFrame,
          "Could not read file '" + file + "'",
          "Unable to read file '" + file + "': " + ex);
    }

    // Set the main frame title, based on the filename and the index.
    mainFrame.setTitle(
        basicTitle
            + ": "
            + file.getName()
            + " ("
            + String.format("%,d", currentCSV.getRowIndex().getRowCount())
            + " rows)");
  }
Ejemplo n.º 2
0
  public void addClient() {
    client =
        new Canvas() {
          public void paint(Graphics g) {
            super.paint(g);
          }
        };
    client.setBackground(new Color(30, 220, 40));
    clientCont.add(client);
    clientCont.validate();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    WindowIDProvider pid = (WindowIDProvider) acc.getPeer(client);
    log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow());
    Rectangle toFocusBounds = toFocus.getBounds();
    toFocusBounds.setLocation(toFocus.getLocationOnScreen());
    f.validate();

    // KDE doesn't accept clicks on title as activation - click below title
    Rectangle fbounds = f.getBounds();
    fbounds.y += f.getInsets().top;
    fbounds.height -= f.getInsets().top;

    Process proc =
        startClient(
            new Rectangle[] {
              fbounds,
              dummy.getBounds(),
              toFocusBounds,
              new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()),
              new Rectangle(10, 130, 20, 20)
            },
            pid.getWindow());
    new ClientWatcher(client, proc, clientCont).start();
  }
Ejemplo n.º 3
0
 public void dispose() {
   f.dispose();
   f = null;
   dummy.dispose();
   dummy = null;
   if (modal_d != null) {
     modal_d.dispose();
     modal_d = null;
   }
 }
Ejemplo n.º 4
0
 public void init() {
   DragSource dragSource = DragSource.getDefaultDragSource();
   // 将srcLabel转换成拖放源,它能接受复制、移动两种操作
   dragSource.createDefaultDragGestureRecognizer(
       srcLabel,
       DnDConstants.ACTION_COPY_OR_MOVE,
       new DragGestureListener() {
         public void dragGestureRecognized(DragGestureEvent event) {
           // 将JLabel里的文本信息包装成Transferable对象
           String txt = srcLabel.getText();
           Transferable transferable = new StringSelection(txt);
           // 继续拖放操作,拖放过程中使用手状光标
           event.startDrag(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR), transferable);
         }
       });
   jf.add(new JScrollPane(srcLabel));
   jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   jf.pack();
   jf.setVisible(true);
 }
Ejemplo n.º 5
0
 public void userHasLogged(String user) {
   boolean isAnonymous = "".equals(StringUtils.parseName(user));
   String title =
       "Smack Debug Window -- "
           + (isAnonymous ? "" : StringUtils.parseBareAddress(user))
           + "@"
           + connection.getServiceName()
           + ":"
           + connection.getPort();
   title += "/" + StringUtils.parseResource(user);
   frame.setTitle(title);
 }
  public static void createAndShowGUI() {
    // Make sure we have nice window decorations.
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
      JFrame.setDefaultLookAndFeelDecorated(true);
    }

    // JFrame.setDefaultLookAndFeelDecorated(true);
    // Create and set up the window.
    DnDTestWindow frame = new DnDTestWindow();

    // Display the window.
    frame.setVisible(true);
  }
Ejemplo n.º 7
0
 public static void createAndShowGUI() {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch (ClassNotFoundException
       | InstantiationException
       | IllegalAccessException
       | UnsupportedLookAndFeelException ex) {
     ex.printStackTrace();
   }
   JFrame frame = new JFrame("@title@");
   frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   frame.getContentPane().add(new MainPanel());
   frame.pack();
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
 }
Ejemplo n.º 8
0
 public static void main(String[] args) {
   JFrame frame = new JFrame();
   frame.setTitle("DragLabel test");
   Container cont = frame.getContentPane();
   DragLabel l = new DragLabel("Here is some text");
   l.setBackground(Color.black);
   l.setForeground(Color.yellow);
   cont.add(l);
   frame.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   frame.setSize(300, 300);
   frame.setVisible(true);
 }
Ejemplo n.º 9
0
  public static void main(String args[]) {

    JFrame frame = new JFrame("Drag Image");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();

    final JLabel label = new JLabel();
    //    Icon icon = new ImageIcon("/home/j2ee/Desktop/war.103.gif");
    //    label.setIcon(icon);
    label.setTransferHandler(new ImageSelection());

    MouseListener mouseListener =
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            JComponent comp = (JComponent) e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, e, TransferHandler.COPY);
          }
        };
    label.addMouseListener(mouseListener);

    JScrollPane pane = new JScrollPane(label);
    contentPane.add(pane, BorderLayout.CENTER);

    JButton copy = new JButton("Copy");
    copy.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            // fire TransferHandler's built-in copy
            // action with a new actionEvent having
            // "label" as the source
            Action copyAction = TransferHandler.getCopyAction();
            copyAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) copyAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JButton clear = new JButton("Clear");
    clear.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            label.setIcon(null);
          }
        });

    JButton paste = new JButton("Paste");
    paste.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            // use TransferHandler's built-in
            // paste action
            Action pasteAction = TransferHandler.getPasteAction();
            pasteAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) pasteAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JPanel p = new JPanel();
    p.add(copy);
    p.add(clear);
    p.add(paste);
    contentPane.add(p, BorderLayout.SOUTH);

    frame.setSize(300, 300);
    frame.show();
  }
Ejemplo n.º 10
0
  /**
   * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup
   * memory monitor components, then starts things off.
   */
  public MainFrame() {
    setupMemoryMonitor();

    // Set up the main frame.
    mainFrame = new JFrame(basicTitle);
    mainFrame.setJMenuBar(setupMenuBar());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the JTable.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setSelectionBackground(COLOR_SELECTION_BACKGROUND);
    table.setShowGrid(true);

    // Add a blank table model so that the component renders properly on
    // startup.
    table.setModel(blankDataModel);

    // Add a list selection listener so we can tell the matchInfoPanel
    // that a new name was selected.
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (currentCSV == null) return;

                int row = table.getSelectedRow();
                int column = table.getSelectedColumn();

                columnInfoPanel.columnChanged(column);

                Object o = table.getModel().getValueAt(row, column);
                if (Name.class.isAssignableFrom(o.getClass())) {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column);
                } else {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1);
                }
              }
            });

    // Set up the left panel (table + matchInfoPanel)
    JPanel leftPanel = new JPanel();

    matchInfoPanel = new MatchInformationPanel(this);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(matchInfoPanel, BorderLayout.SOUTH);
    leftPanel.add(new JScrollPane(table));

    // Set up the right panel (columnInfoPanel)
    JPanel rightPanel = new JPanel();

    columnInfoPanel = new ColumnInformationPanel(this);

    progressBar.setStringPainted(true);

    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(columnInfoPanel);
    rightPanel.add(progressBar, BorderLayout.SOUTH);

    // Set up a JSplitPane to split the panels up.
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel);
    split.setResizeWeight(1);
    mainFrame.add(split);
    mainFrame.pack();

    // Set up a drop target so we can pick up files
    mainFrame.setDropTarget(
        new DropTarget(
            mainFrame,
            new DropTargetAdapter() {
              @Override
              public void dragEnter(DropTargetDragEvent dtde) {
                // Accept any drags.
                dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
              }

              @Override
              public void dragOver(DropTargetDragEvent dtde) {}

              @Override
              public void dropActionChanged(DropTargetDragEvent dtde) {}

              @Override
              public void dragExit(DropTargetEvent dte) {}

              @Override
              public void drop(DropTargetDropEvent dtde) {
                // Accept a drop as long as its File List.

                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                  dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

                  Transferable t = dtde.getTransferable();

                  try {
                    java.util.List<File> files =
                        (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);

                    // If we're given multiple files, pick up only the last file and load that.
                    File f = files.get(files.size() - 1);
                    loadFile(f, DarwinCSV.FILE_CSV_DELIMITED);

                  } catch (UnsupportedFlavorException ex) {
                    dtde.dropComplete(false);

                  } catch (IOException ex) {
                    dtde.dropComplete(false);
                  }
                }
              }
            }));
  }
Ejemplo n.º 11
0
  public TestXEmbedServer(boolean manual) {

    // Enable testing extensions in XEmbed server
    System.setProperty("sun.awt.xembed.testing", "true");

    f = new Frame("Main frame");
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            synchronized (TestXEmbedServer.this) {
              TestXEmbedServer.this.notifyAll();
            }
            dummy.dispose();
            f.dispose();
          }
        });

    f.setLayout(new BorderLayout());

    Container bcont = new Container();

    toFocus = new Button("Click to focus server");
    final TextField tf = new TextField(20);
    tf.setName("0");
    DragSource ds = new DragSource();
    final DragSourceListener dsl =
        new DragSourceAdapter() {
          public void dragDropEnd(DragSourceDropEvent dsde) {}
        };
    final DragGestureListener dgl =
        new DragGestureListener() {
          public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection(tf.getText()), dsl);
          }
        };
    ds.createDefaultDragGestureRecognizer(tf, DnDConstants.ACTION_COPY, dgl);

    final DropTargetListener dtl =
        new DropTargetAdapter() {
          public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            try {
              tf.setText(
                  tf.getText()
                      + (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor));
            } catch (Exception e) {
            }
          }
        };
    final DropTarget dt = new DropTarget(tf, dtl);

    Button b_add = new Button("Add client");
    b_add.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            addClient();
          }
        });
    Button b_remove = new Button("Remove client");
    b_remove.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (clientCont.getComponentCount() != 0) {
              clientCont.remove(clientCont.getComponentCount() - 1);
            }
          }
        });
    b_close = new JButton("Close modal dialog");
    b_close.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modal_d.dispose();
          }
        });
    b_modal = new Button("Show modal dialog");
    b_modal.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modal_d = new JDialog(f, "Modal dialog", true);
            modal_d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            modal_d.setBounds(0, 100, 200, 50);
            modal_d.getContentPane().add(b_close);
            modal_d.validate();
            modal_d.show();
          }
        });

    bcont.add(tf);
    bcont.add(toFocus);
    bcont.add(b_add);
    bcont.add(b_remove);
    bcont.add(b_modal);
    if (manual) {
      Button pass = new Button("Pass");
      pass.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              passed = true;
              synchronized (TestXEmbedServer.this) {
                TestXEmbedServer.this.notifyAll();
              }
            }
          });
      bcont.add(pass);
      Button fail = new Button("Fail");
      fail.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              passed = false;
              synchronized (TestXEmbedServer.this) {
                TestXEmbedServer.this.notifyAll();
              }
            }
          });
      bcont.add(fail);
    }
    b_modal.setName("2");
    bcont.setLayout(new FlowLayout());
    f.add(bcont, BorderLayout.NORTH);

    clientCont = Box.createVerticalBox();
    f.add(clientCont, BorderLayout.CENTER);

    dummy = new JFrame("Dummy");
    dummy.getContentPane().add(new JButton("Button"));
    dummy.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dummy.setBounds(0, VERTICAL_POSITION, 100, 100);
    dummy.setVisible(true);

    f.setBounds(300, VERTICAL_POSITION, 800, 300);
    f.setVisible(true);
  }
Ejemplo n.º 12
0
  /** Creates the debug process, which is a GUI window that displays XML traffic. */
  private void createDebug() {
    frame =
        new JFrame(
            "Smack Debug Window -- " + connection.getServiceName() + ":" + connection.getPort());

    // Add listener for window closing event
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            rootWindowClosing(evt);
          }
        });

    // We'll arrange the UI into four tabs. The first tab contains all data, the second
    // client generated XML, the third server generated XML, and the fourth is packet
    // data from the server as seen by Smack.
    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel allPane = new JPanel();
    allPane.setLayout(new GridLayout(3, 1));
    tabbedPane.add("All", allPane);

    // Create UI elements for client generated XML traffic.
    final JTextArea sentText1 = new JTextArea();
    final JTextArea sentText2 = new JTextArea();
    sentText1.setEditable(false);
    sentText2.setEditable(false);
    sentText1.setForeground(new Color(112, 3, 3));
    sentText2.setForeground(new Color(112, 3, 3));
    allPane.add(new JScrollPane(sentText1));
    tabbedPane.add("Sent", new JScrollPane(sentText2));

    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(sentText1.getText()), null);
          }
        });

    JMenuItem menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sentText1.setText("");
            sentText2.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(menu);
    sentText1.addMouseListener(popupListener);
    sentText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create UI elements for server generated XML traffic.
    final JTextArea receivedText1 = new JTextArea();
    final JTextArea receivedText2 = new JTextArea();
    receivedText1.setEditable(false);
    receivedText2.setEditable(false);
    receivedText1.setForeground(new Color(6, 76, 133));
    receivedText2.setForeground(new Color(6, 76, 133));
    allPane.add(new JScrollPane(receivedText1));
    tabbedPane.add("Received", new JScrollPane(receivedText2));

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(receivedText1.getText()), null);
          }
        });

    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            receivedText1.setText("");
            receivedText2.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    popupListener = new PopupListener(menu);
    receivedText1.addMouseListener(popupListener);
    receivedText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create UI elements for interpreted XML traffic.
    final JTextArea interpretedText1 = new JTextArea();
    final JTextArea interpretedText2 = new JTextArea();
    interpretedText1.setEditable(false);
    interpretedText2.setEditable(false);
    interpretedText1.setForeground(new Color(1, 94, 35));
    interpretedText2.setForeground(new Color(1, 94, 35));
    allPane.add(new JScrollPane(interpretedText1));
    tabbedPane.add("Interpreted", new JScrollPane(interpretedText2));

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(interpretedText1.getText()), null);
          }
        });

    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            interpretedText1.setText("");
            interpretedText2.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    popupListener = new PopupListener(menu);
    interpretedText1.addMouseListener(popupListener);
    interpretedText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);

    frame.getContentPane().add(tabbedPane);

    frame.setSize(550, 400);
    frame.setVisible(true);

    // Create a special Reader that wraps the main Reader and logs data to the GUI.
    ObservableReader debugReader = new ObservableReader(reader);
    readerListener =
        new ReaderListener() {
          public void read(String str) {
            int index = str.lastIndexOf(">");
            if (index != -1) {
              receivedText1.append(str.substring(0, index + 1));
              receivedText2.append(str.substring(0, index + 1));
              receivedText1.append(NEWLINE);
              receivedText2.append(NEWLINE);
              if (str.length() > index) {
                receivedText1.append(str.substring(index + 1));
                receivedText2.append(str.substring(index + 1));
              }
            } else {
              receivedText1.append(str);
              receivedText2.append(str);
            }
          }
        };
    debugReader.addReaderListener(readerListener);

    // Create a special Writer that wraps the main Writer and logs data to the GUI.
    ObservableWriter debugWriter = new ObservableWriter(writer);
    writerListener =
        new WriterListener() {
          public void write(String str) {
            sentText1.append(str);
            sentText2.append(str);
            if (str.endsWith(">")) {
              sentText1.append(NEWLINE);
              sentText2.append(NEWLINE);
            }
          }
        };
    debugWriter.addWriterListener(writerListener);

    // Assign the reader/writer objects to use the debug versions. The packet reader
    // and writer will use the debug versions when they are created.
    reader = debugReader;
    writer = debugWriter;

    // Create a thread that will listen for all incoming packets and write them to
    // the GUI. This is what we call "interpreted" packet data, since it's the packet
    // data as Smack sees it and not as it's coming in as raw XML.
    listener =
        new PacketListener() {
          public void processPacket(Packet packet) {
            interpretedText1.append(packet.toXML());
            interpretedText2.append(packet.toXML());
            interpretedText1.append(NEWLINE);
            interpretedText2.append(NEWLINE);
          }
        };
  }