public void mouseEntered(MouseEvent evt) {
   if (list != null) {
     TransferHandler th1 = getFileChooser().getTransferHandler();
     TransferHandler th2 = list.getTransferHandler();
     if (th1 != th2) {
       list.setTransferHandler(th1);
     }
     if (getFileChooser().getDragEnabled() != list.getDragEnabled()) {
       list.setDragEnabled(getFileChooser().getDragEnabled());
     }
   }
 }
  /**
   * Sets up the JTree.
   *
   * @return
   */
  JList getContent() {

    model = new DefaultListModel();
    list = new JList(model);

    // Only select one song in playlist at a time
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    list.setDragEnabled(true);
    list.setDropMode(DropMode.INSERT);

    // Add drag and drop support
    list.setTransferHandler(new ListTransferHandler(list, callback, gui));

    list.setCellRenderer(new PlayListCellRenderer());
    list.setBorder(null);

    list.addMouseListener(
        new MouseAdapter() {
          private PlayListPopUpMenu popup = new PlayListPopUpMenu();

          /** Display pop up menu for songs */
          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              JList source = (JList) e.getSource();
              source.setSelectedIndex(source.locationToIndex(e.getPoint()));
              popup.show(source, e.getX(), e.getY());
            }
          }

          /** Play songs that are double clicked */
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              int index = list.locationToIndex(e.getPoint());
              Song selectedSong = (Song) list.getModel().getElementAt(index);

              model.remove(index);

              model.add(model.size(), selectedSong);

              callback.notify(
                  Command.NEW_QUEUE, Arrays.asList(model.toArray()), gui.getCurrentZone());
            }
          }
        });

    return list;
  }
Example #3
0
  public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            textArea.setText("");
          }
        });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
  }
Example #4
0
 <T> JList createJList(String title, List<T> data) {
   JList list = new JList();
   list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   list.setDragEnabled(false);
   // HACK find a way to modify napkin's color, not the component's
   int c = 200;
   list.setSelectionBackground(new Color(c, c, c));
   list.setBorder(BorderFactory.createTitledBorder(title));
   if (data != null) {
     List<T> objects = new ArrayList<T>(data);
     Collections.sort(
         objects,
         new Comparator<T>() {
           @Override
           public int compare(T arg0, T arg1) {
             return arg0.toString().compareTo(arg1.toString());
           }
         });
     list.setListData(objects.toArray());
   }
   return list;
 }
  public SQLiteDataBrowser() {
    SQLiteDbManager dbManager = new SQLiteDbManager();

    setLayout(new BorderLayout());

    showTablesList = new JList();
    showTablesList.setLayoutOrientation(JList.VERTICAL_WRAP);
    showTablesList.setSelectedIndex(ListSelectionModel.SINGLE_SELECTION);
    showTablesList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    showTablesList.setFont(new Font("Times New Roman", Font.PLAIN, 13));
    showTablesList.setDragEnabled(false);
    showTablesList.setFixedCellWidth(150);
    showTablesList.setVisibleRowCount(-1);
    showTablesList.setEnabled(false);

    showTablesListScroller = new JScrollPane(showTablesList);
    showTablesListScroller.setBorder(
        BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "List of Tables"));
    showTablesListScroller.setPreferredSize(new Dimension(160, this.getHeight()));

    add(showTablesListScroller, BorderLayout.EAST);

    loadDbPanel = new JPanel(new FlowLayout());
    loadDbPanel.setBackground(new Color(0xe8e8e8));
    loadDbPanel.setPreferredSize(new Dimension(getWidth(), 40));

    loadDbLabel = new JLabel("Load SQLite Database: ");
    loadDbLabel.setToolTipText("Possible extensions being .sqlite|.sqlite3|.db|.db3");

    loadedDbPath = new JTextField("Click browse to choose the database file.", 60);
    loadedDbPath.setForeground(Color.GRAY);
    loadedDbPath.setFont(new Font("Times New Roman", Font.ITALIC, 13));
    loadedDbPath.setEditable(false);

    lastFolderLocation = new File(Utils.getUserHome());
    fc = new JFileChooser(lastFolderLocation);

    browseDb = new JButton("Browse");
    browseDb.addActionListener(
        actionEvent -> {
          int retVal = fc.showOpenDialog(SQLiteDataBrowser.this);
          if (retVal == JFileChooser.APPROVE_OPTION) {
            File dbPath = fc.getSelectedFile();
            if (Utils.checkIfSQLiteDb(dbPath)) {
              loadedDbPath.setText(dbPath.toString());
              lastFolderLocation = fc.getCurrentDirectory();
              new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                  try {
                    dbManager.setDbPath(dbPath.toString());
                    dbManager.initialize();
                    showTablesList.setListData(dbManager.getTables().toArray());
                    showTablesList.setEnabled(true);
                  } catch (SQLException e) {
                    e.printStackTrace();
                  }
                  return null;
                }
              }.execute();
            } else {
              JOptionPane.showMessageDialog(
                  SQLiteDataBrowser.this,
                  "The Selected file is not in SQLite Format",
                  "File Format Error",
                  JOptionPane.ERROR_MESSAGE);
              loadedDbPath.setText("Click browse to choose the database file.");
            }
          }
        });

    loadDbPanel.add(loadDbLabel);
    loadDbPanel.add(loadedDbPath);
    loadDbPanel.add(browseDb);

    loadDbRecords = new JLabel("Records Fetched (Rows x Cols): ");
    loadDbRecords.setFont(new Font("Times New Roman", Font.ITALIC, 12));
    loadDbPanel.add(loadDbRecords);

    loadDbRecordsCount = new JLabel();
    loadDbRecordsCount.setFont(new Font("Times New Roman", Font.ITALIC, 12));
    loadDbPanel.add(loadDbRecordsCount);

    final class DataBrowserTableModal extends DefaultTableModel {

      public DataBrowserTableModal() {}

      public DataBrowserTableModal(Object[][] tableData, Object[] colNames) {
        super(tableData, colNames);
      }

      @Override
      public void setDataVector(Object[][] tableData, Object[] colNames) {
        super.setDataVector(tableData, colNames);
      }

      @Override
      public boolean isCellEditable(int row, int column) {
        return false;
      }
    }

    DataBrowserTableModal tableModal = new DataBrowserTableModal();
    defaultTableModel = tableModal;

    table = new JTable();
    table.setModel(defaultTableModel);

    showTablesList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            JList list = (JList) evt.getSource();
            if (evt.getClickCount() == 2) {
              String tableName = list.getSelectedValue().toString();

              new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                  try {
                    ResultSet rs = dbManager.executeQuery("SELECT * from " + tableName);
                    Vector<String> columnNames = dbManager.getColumnNames(rs);
                    Vector<Vector<Object>> tableData = new Vector<>();
                    while (rs.next()) {
                      Vector<Object> vector = new Vector<>();

                      for (int i = 1; i <= columnNames.size(); i++) {
                        vector.add(rs.getObject(i));
                      }
                      tableData.add(vector);
                    }
                    defaultTableModel.setDataVector(tableData, columnNames);
                  } catch (SQLException e) {
                    e.printStackTrace();
                  }

                  loadDbRecordsCount.setText(
                      defaultTableModel.getRowCount() + " x " + defaultTableModel.getColumnCount());

                  if (defaultTableModel.getColumnCount() < 5) {
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                  } else {
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                  }

                  return null;
                }
              }.execute();
            }
          }
        });

    tableScrollPane = new JScrollPane(table);
    tableScrollPane.setHorizontalScrollBarPolicy(
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    tableScrollPane.setPreferredSize(new Dimension(getWidth(), getHeight()));
    add(tableScrollPane, BorderLayout.CENTER);

    add(loadDbPanel, BorderLayout.NORTH);
  }
Example #6
0
  public ShowResults(SharkPanel _sp, String _files[], double _scores[], int _nrpairs[]) {
    sp = _sp;
    files = _files;
    scores = _scores;
    nrpairs = _nrpairs;
    LogFile lf = new LogFile("SearchResults_");
    DefaultListModel listModel = new DefaultListModel();
    for (int i = 0; i < files.length; i++) {
      GetImageFile gif = new GetImageFile(files[i]);
      Integer ii = new Integer(_nrpairs[i]);
      int tmpval = (int) (1000.0 * _scores[i]);
      Double dd = new Double((double) tmpval / 1000.0);
      String tmp = gif.getImageString();
      String s =
          tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length())
              + "\t"
              + ii.toString()
              + "\t"
              + dd.toString();
      String ddval = dd.toString();
      while (ddval.length() < 5) ddval += "0";
      if (i < 9)
        listModel.addElement(
            "  "
                + (i + 1)
                + ".  "
                + ddval
                + "   "
                + tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length()));
      else
        listModel.addElement(
            (i + 1)
                + ".  "
                + ddval
                + "   "
                + tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length()));
      lf.write(s);
    }
    lf.close();

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setDragEnabled(false);
    list.addMouseListener(new MouseClickListener());

    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(250, 250));

    showButton = new JButton("Visual comparison");
    showButton.addActionListener(this);
    showButton.setMnemonic('V');
    showButton.setEnabled(false);

    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(this);
    closeButton.setMnemonic('C');

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.add(listView, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel panel2 = new JPanel();
    panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
    panel2.add(showButton);
    panel2.add(Box.createRigidArea(new Dimension(10, 1)));
    panel2.add(closeButton);

    add(panel);
    add(Box.createRigidArea(new Dimension(1, 10)));
    add(panel2);

    if (frame != null) frame.dispose();
    frame = new JFrame("I3S: Search results");
    frame.setContentPane(this);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            frame.dispose();
            frame = null;
          }
        });
    frame.setSize(new Dimension(400, 300));
    frame.setLocation(200, 200);

    ImageIcon imageIcon = new ImageIcon(this.getClass().getResource("/Simages/icon.gif"));
    frame.setIconImage(imageIcon.getImage());

    frame.pack();
    frame.setVisible(true);
  }
Example #7
0
  public ThumbMaker() {
    super("ThumbMaker");

    // grab the preferences so that they can be used to fill out the layout
    ThumbMakerPreferences myPrefs = ThumbMakerPreferences.getInstance();

    // content pane
    JPanel pane = new JPanel();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    setContentPane(pane);

    // top panel
    JPanel top = new JPanel();
    top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
    pane.add(top);

    // left-hand panel
    JPanel left = new JPanel();
    left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
    top.add(left);

    // horizontal padding
    top.add(Box.createHorizontalStrut(5));

    // label for file list
    JLabel listLabel = GUIUtil.makeLabel("Files to process:");
    listLabel.setDisplayedMnemonic('f');
    String listTip = "List of files from which to create thumbnails";
    listLabel.setToolTipText(listTip);
    left.add(GUIUtil.pad(listLabel));

    // list of files to convert
    list = new JList();
    listLabel.setLabelFor(list);
    list.setToolTipText(listTip);
    list.setModel(new DefaultListModel());
    list.setDragEnabled(true);
    changeFilesInList = new ThumbTransferHandler();
    list.setTransferHandler(changeFilesInList);
    left.add(new JScrollPane(list));

    // progress bar
    progress = new JProgressBar(0, 1);
    progress.setString("[Drag and drop files onto list to begin]");
    progress.setStringPainted(true);
    progress.setToolTipText("Status of thumbnail processing operation");
    left.add(progress);

    // panel for process and remove buttons
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    // add files button
    addFiles = new JButton("Add Files");
    addFiles.setMnemonic('d');
    addFiles.setToolTipText("Add files to be processed.");
    addFiles.addActionListener(this);
    p.add(addFiles);

    p.add(Box.createHorizontalStrut(5));

    // process button
    process = new JButton("Process");
    process.setMnemonic('p');
    process.setToolTipText("Begin creating thumbnails");
    process.addActionListener(this);
    p.add(process);

    p.add(Box.createHorizontalStrut(5));

    // remove button
    remove = new JButton("Remove");
    remove.setMnemonic('v');
    remove.setToolTipText("Remove selected files from the list");
    remove.addActionListener(this);
    p.add(remove);

    left.add(GUIUtil.pad(p));

    // right-hand panel
    JPanel right = new JPanel();
    right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));
    top.add(right);

    // panel for resolution settings
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    // resolution label
    JLabel resLabel = GUIUtil.makeLabel("Resolution: ");
    resLabel.setDisplayedMnemonic('s');
    resLabel.setToolTipText("Resolution of the thumbnails");
    p.add(resLabel);

    // x resolution text box
    xres =
        GUIUtil.makeTextField(myPrefs.getStringPref(ThumbMakerPreferences.RES_WIDTH_PREF_NAME), 2);
    resLabel.setLabelFor(xres);
    xres.setToolTipText("Thumbnail width");
    p.add(xres);

    // "by" label
    JLabel byLabel = GUIUtil.makeLabel(" by ");
    byLabel.setDisplayedMnemonic('y');
    p.add(byLabel);

    // y resolution text box
    yres =
        GUIUtil.makeTextField(myPrefs.getStringPref(ThumbMakerPreferences.RES_HEIGHT_PREF_NAME), 2);
    byLabel.setLabelFor(yres);
    yres.setToolTipText("Thumbnail height");
    p.add(yres);

    right.add(GUIUtil.pad(p));
    right.add(Box.createVerticalStrut(8));

    // aspect ratio checkbox
    aspect = new JCheckBox("Maintain aspect ratio", true);
    aspect.setMnemonic('m');
    aspect.setToolTipText(
        "When checked, thumbnails are not stretched, "
            + "but rather padded with the background color.");
    aspect.addActionListener(this);
    right.add(GUIUtil.pad(aspect));
    // make sure that the check box is initialized correctly
    aspect.setSelected(
        myPrefs
            .getStringPref(ThumbMakerPreferences.DO_MAINTAIN_ASPECT_PREF_NAME)
            .equalsIgnoreCase(ThumbMakerPreferences.BOOLEAN_TRUE_STRING));

    // panel for background color
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    // load the color values from the preferences
    int redValueNumber = myPrefs.getIntegerPref(ThumbMakerPreferences.RED_VALUE_PREF_NAME);
    int greenValueNumber = myPrefs.getIntegerPref(ThumbMakerPreferences.GREEN_VALUE_PREF_NAME);
    int blueValueNumber = myPrefs.getIntegerPref(ThumbMakerPreferences.BLUE_VALUE_PREF_NAME);

    // background color label
    colorLabel = GUIUtil.makeLabel("Background color: ");
    String colorTip = "Thumbnail background color";
    colorLabel.setToolTipText(colorTip);
    p.add(colorLabel);

    // background color
    colorBox = new JPanel();
    colorBox.setToolTipText(colorTip);
    colorBox.setBorder(new LineBorder(Color.black, 1));
    Dimension colorBoxSize = new Dimension(45, 15);
    colorBox.setMaximumSize(colorBoxSize);
    colorBox.setMinimumSize(colorBoxSize);
    colorBox.setPreferredSize(colorBoxSize);
    colorBox.setBackground(new Color(redValueNumber, greenValueNumber, blueValueNumber));
    p.add(colorBox);

    right.add(GUIUtil.pad(p));
    right.add(Box.createVerticalStrut(2));

    // red slider
    redLabel = GUIUtil.makeLabel("R");
    red = new JSlider(0, 255, redValueNumber);
    redValue = GUIUtil.makeLabel("" + redValueNumber);
    redValue.setToolTipText("Red color component slider");
    right.add(makeSlider(redLabel, red, redValue, "Red"));

    // green slider
    greenLabel = GUIUtil.makeLabel("G");
    green = new JSlider(0, 255, greenValueNumber);
    greenValue = GUIUtil.makeLabel("" + greenValueNumber);
    greenValue.setToolTipText("Green color component slider");
    right.add(makeSlider(greenLabel, green, greenValue, "Green"));

    // blue slider
    blueLabel = GUIUtil.makeLabel("B");
    blue = new JSlider(0, 255, blueValueNumber);
    blueValue = GUIUtil.makeLabel("" + blueValueNumber);
    right.add(makeSlider(blueLabel, blue, blueValue, "Blue"));

    right.add(Box.createVerticalStrut(8));

    // panel for algorithm
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    // algorithm label
    JLabel algorithmLabel = GUIUtil.makeLabel("Algorithm: ");
    algorithmLabel.setDisplayedMnemonic('l');
    String algorithmTip = "Resizing algorithm to use";
    algorithmLabel.setToolTipText(algorithmTip);
    p.add(algorithmLabel);

    // algorithm combo box
    algorithm =
        GUIUtil.makeComboBox(
            new String[] {"Smooth", "Standard", "Fast", "Replicate", "Area averaging"});
    algorithmLabel.setLabelFor(algorithm);
    algorithm.setToolTipText(algorithmTip);
    p.add(algorithm);
    // set the algorithm value from the preferences
    algorithm.setSelectedIndex(myPrefs.getIntegerPref(ThumbMakerPreferences.RESIZE_ALG_PREF_NAME));

    right.add(GUIUtil.pad(p));

    // panel for output format
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    // format label
    JLabel formatLabel = GUIUtil.makeLabel("Format: ");
    formatLabel.setDisplayedMnemonic('f');
    String formatTip = "Thumbnail output format";
    formatLabel.setToolTipText(formatTip);
    p.add(formatLabel);

    // format combo box
    format = GUIUtil.makeComboBox(new String[] {"PNG", "JPG"});
    formatLabel.setLabelFor(format);
    format.setToolTipText(formatTip);
    p.add(format);
    // set the format value from the preferences
    format.setSelectedIndex(myPrefs.getIntegerPref(ThumbMakerPreferences.THUMB_FORMAT_PREF_NAME));

    right.add(GUIUtil.pad(p));
    right.add(Box.createVerticalStrut(5));

    // panel for prepend string
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    // prepend label
    JLabel prependLabel = GUIUtil.makeLabel("Prepend: ");
    prependLabel.setDisplayedMnemonic('e');
    String prependTip = "Starting string for each thumbnail filename";
    prependLabel.setToolTipText(prependTip);
    p.add(prependLabel);

    // prepend field
    prepend =
        GUIUtil.makeTextField(
            myPrefs.getStringPref(ThumbMakerPreferences.STRING_TO_PREPEND_PREF_NAME), 4);
    prependLabel.setLabelFor(prepend);
    prepend.setToolTipText(prependTip);
    p.add(prepend);

    p.add(Box.createHorizontalStrut(5));

    // append label
    JLabel appendLabel = GUIUtil.makeLabel("Append: ");
    appendLabel.setDisplayedMnemonic('a');
    String appendTip = "Ending string for each thumbnail filename";
    appendLabel.setToolTipText(appendTip);
    p.add(appendLabel);

    // append field
    append =
        GUIUtil.makeTextField(
            myPrefs.getStringPref(ThumbMakerPreferences.STRING_TO_APPEND_PREF_NAME), 4);
    appendLabel.setLabelFor(append);
    append.setToolTipText(appendTip);
    p.add(append);

    right.add(GUIUtil.pad(p));

    // vertical padding
    right.add(Box.createVerticalGlue());

    // bottom panel
    JPanel bottom = new JPanel();
    bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
    pane.add(bottom);

    // output folder label
    JLabel outputLabel = GUIUtil.makeLabel("Output folder: ");
    outputLabel.setDisplayedMnemonic('o');
    String outputTip = "Thumbnail output folder";
    outputLabel.setToolTipText(outputTip);
    bottom.add(outputLabel);

    // output folder field
    String filePath =
        new File(myPrefs.getStringPref(ThumbMakerPreferences.FILE_PATH_STRING_PREF_NAME))
            .getAbsolutePath();
    output = GUIUtil.makeTextField(filePath, 8);
    outputLabel.setLabelFor(output);
    output.setToolTipText(outputTip);
    // start this in default and then lock down so "..." is used
    output.setEditable(false);
    output.setBackground(Color.LIGHT_GRAY);
    bottom.add(output);

    // add a file chooser button "..."
    dotDotDot = new JButton("...");
    dotDotDot.setMnemonic('.');
    dotDotDot.setToolTipText("Select destination directory.");
    dotDotDot.addActionListener(this);
    bottom.add(dotDotDot);

    right.add(GUIUtil.pad(p));

    setFromPreferences();
    addWindowListener(this);
  }
Example #8
0
  @SuppressWarnings("unchecked") // FIXME in Java7
  public BuildQueuePanel(FreeColClient freeColClient, GUI gui, Colony colony) {

    super(
        freeColClient,
        gui,
        new MigLayout("wrap 3", "[260:][390:, fill][260:]", "[][][300:400:][]"));
    this.colony = colony;
    this.unitCount = colony.getUnitCount();
    featureContainer = new FeatureContainer();

    for (UnitType unitType : getSpecification().getUnitTypeList()) {
      if (unitType.needsGoodsToBuild() && !unitType.hasAbility(Ability.BORN_IN_COLONY)) {
        buildableUnits.add(unitType); // can be built
      }
    }

    DefaultListModel current = new DefaultListModel();
    for (BuildableType type : colony.getBuildQueue()) {
      current.addElement(type);
      FeatureContainer.addFeatures(featureContainer, type);
    }

    cellRenderer = getCellRenderer();

    // remove previous listeners
    for (ItemListener listener : compact.getItemListeners()) {
      compact.removeItemListener(listener);
    }
    compact.setText(Messages.message("colonyPanel.compactView"));
    compact.addItemListener(this);

    // remove previous listeners
    for (ItemListener listener : showAll.getItemListeners()) {
      showAll.removeItemListener(listener);
    }
    showAll.setText(Messages.message("colonyPanel.showAll"));
    showAll.addItemListener(this);

    buildQueueList = new JList(current);
    buildQueueList.setTransferHandler(buildQueueHandler);
    buildQueueList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    buildQueueList.setDragEnabled(true);
    buildQueueList.setCellRenderer(cellRenderer);
    buildQueueList.addMouseListener(new BuildQueueMouseAdapter(false));

    Action deleteAction =
        new AbstractAction() {
          @SuppressWarnings("deprecation") // FIXME in Java7
          public void actionPerformed(ActionEvent e) {
            for (Object type : buildQueueList.getSelectedValues()) {
              removeBuildable(type);
            }
            updateAllLists();
          }
        };

    buildQueueList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "delete");
    buildQueueList.getActionMap().put("delete", deleteAction);

    Action addAction =
        new AbstractAction() {
          @SuppressWarnings("deprecation") // FIXME in Java7
          public void actionPerformed(ActionEvent e) {
            DefaultListModel model = (DefaultListModel) buildQueueList.getModel();
            for (Object type : ((JList) e.getSource()).getSelectedValues()) {
              model.addElement(type);
            }
            updateAllLists();
          }
        };

    BuildQueueMouseAdapter adapter = new BuildQueueMouseAdapter(true);
    DefaultListModel units = new DefaultListModel();
    unitList = new JList(units);
    unitList.setTransferHandler(buildQueueHandler);
    unitList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    unitList.setDragEnabled(true);
    unitList.setCellRenderer(cellRenderer);
    unitList.addMouseListener(adapter);

    unitList.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "add");
    unitList.getActionMap().put("add", addAction);

    DefaultListModel buildings = new DefaultListModel();
    buildingList = new JList(buildings);
    buildingList.setTransferHandler(buildQueueHandler);
    buildingList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    buildingList.setDragEnabled(true);
    buildingList.setCellRenderer(cellRenderer);
    buildingList.addMouseListener(adapter);

    buildingList.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "add");
    buildingList.getActionMap().put("add", addAction);

    JLabel headLine = new JLabel(Messages.message("colonyPanel.buildQueue"));
    headLine.setFont(bigHeaderFont);

    buyBuilding = new JButton(Messages.message("colonyPanel.buyBuilding"));
    buyBuilding.setActionCommand(BUY);
    buyBuilding.addActionListener(this);

    constructionPanel = new ConstructionPanel(gui, colony, false);
    constructionPanel.setOpaque(false);
    StringTemplate buildingNothing =
        StringTemplate.template("colonyPanel.currentlyBuilding").add("%buildable%", "nothing");
    constructionPanel.setDefaultLabel(buildingNothing);

    updateAllLists();

    add(headLine, "span 3, align center, wrap 40");
    add(new JLabel(Messages.message("colonyPanel.units")), "align center");
    add(new JLabel(Messages.message("colonyPanel.buildQueue")), "align center");
    add(new JLabel(Messages.message("colonyPanel.buildings")), "align center");
    add(new JScrollPane(unitList), "grow");
    add(constructionPanel, "split 2, flowy");
    add(new JScrollPane(buildQueueList), "grow");
    add(new JScrollPane(buildingList), "grow, wrap 20");
    add(buyBuilding, "span, split 4");
    add(compact);
    add(showAll);
    add(okButton, "tag ok");
  }
  public DatabaseSearchUI() {

    setLayout(new BorderLayout());

    JPanel displayNamePanel = new JPanel(new BorderLayout());
    JLabel displayNameLabel = new JLabel("Base Displayed Name:");
    baseDisplayedNameField = new JTextField();
    baseDisplayedNameField.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (goButton.isEnabled()) goButton.doClick();
          }
        });
    displayNameLabel.setLabelFor(baseDisplayedNameField);
    displayNamePanel.add(baseDisplayedNameField, BorderLayout.CENTER);
    displayNamePanel.add(displayNameLabel, BorderLayout.WEST);

    goButton = new JButton();
    String searchButtonText = "Search"; // bundle.getString("SEARCH_BUTTON");
    goButton.getAccessibleContext().setAccessibleName(searchButtonText);
    goButton.setAction(
        new AbstractAction(searchButtonText) {

          @Override
          public void actionPerformed(ActionEvent e) {
            goButton.setEnabled(false);
            SearchTask task = new SearchTask();
            listModel.removeAllElements();
            resultStatus.setText(null);
            task.execute();
          }
        });
    JPanel displayNameAndGoPanel = new JPanel(new BorderLayout());
    displayNameAndGoPanel.add(displayNamePanel, BorderLayout.CENTER);
    displayNameAndGoPanel.add(goButton, BorderLayout.EAST);

    listModel = new DefaultListModel();
    list = new JList(listModel);
    list.getAccessibleContext().setAccessibleName("Search Result List");
    list.setCellRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            ComponentInfo ci = (ComponentInfo) value;
            JLabel label =
                (JLabel)
                    super.getListCellRendererComponent(
                        list, ci.name, index, isSelected, cellHasFocus);
            label.setIcon(AbstractComponent.getIconForComponentType(ci.type));
            return label;
          }
        });

    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.addListSelectionListener(
        new ListSelectionListener() {

          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
              Collection<View> selectedManifestations = getSelectedManifestations();
              if (!selectedManifestations.isEmpty()) {
                firePropertyChange(
                    SelectionProvider.SELECTION_CHANGED_PROP, null, selectedManifestations);
              } // end if
            } // end if
          }
        });

    list.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            Collection<View> selectedManifestations = getSelectedManifestations();
            if (selectedManifestations.isEmpty()) return;

            View manifestation = selectedManifestations.iterator().next();
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
              manifestation.getManifestedComponent().open();
              return;
            }
          }
        });
    list.setDragEnabled(true);
    list.setTransferHandler(
        new TransferHandler() {
          @Override
          protected Transferable createTransferable(JComponent c) {
            List<View> viewRoles = new ArrayList<View>();
            Collection<View> selectedManifestations = getSelectedManifestations();
            if (!selectedManifestations.isEmpty()) {
              for (View manifestation : getSelectedManifestations()) viewRoles.add(manifestation);
              return new ViewRoleSelection(viewRoles.toArray(new View[viewRoles.size()]));
            } else {
              return null;
            } // end if
          }

          @Override
          public int getSourceActions(JComponent c) {
            return TransferHandler.COPY;
          }
        });

    JPanel controlPanel = new JPanel(new GridLayout(2, 1, 5, 5));
    controlPanel.add(displayNameAndGoPanel);
    findObjectsCreatedByMe = new JCheckBox("Created By Me");
    controlPanel.add(findObjectsCreatedByMe);

    JPanel descriptionPanel = new JPanel(new GridLayout(2, 1));
    JLabel searchEverywhereLabel = new JLabel("Search everywhere");
    searchEverywhereLabel.setFont(searchEverywhereLabel.getFont().deriveFont(Font.BOLD));

    resultStatus = new JLabel();
    resultStatus.setForeground(Color.BLUE);

    descriptionPanel.add(searchEverywhereLabel);
    descriptionPanel.add(resultStatus);

    JPanel upperPanel = new JPanel(new BorderLayout(PADDING, PADDING));
    upperPanel.setBorder(BorderFactory.createEmptyBorder(PADDING, PADDING, PADDING, PADDING));
    upperPanel.add(descriptionPanel, BorderLayout.NORTH);
    upperPanel.add(controlPanel, BorderLayout.CENTER);

    add(upperPanel, BorderLayout.NORTH);
    add(new JScrollPane(list), BorderLayout.CENTER);
  }
Example #10
0
  JPanel getPanel(int infoWidth, int infoHeight) {

    //For layout purposes, put things in separate panels
   
    //Create the list and list view to handle the list of 
    //Jmol Instances.
    instanceList = new JList(new DefaultListModel());
    instanceList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    instanceList.setTransferHandler(new ArrayListTransferHandler(this));
    instanceList.setCellRenderer(new InstanceCellRenderer());
    instanceList.setDragEnabled(true);
    instanceList.setPreferredSize(new Dimension(350, 200));

    JScrollPane instanceListView = new JScrollPane(instanceList);
    instanceListView.setPreferredSize(new Dimension(350, 200));
    JPanel instanceSet = new JPanel();
    instanceSet.setLayout(new BorderLayout());
    instanceSet.add(new JLabel(listLabel), BorderLayout.NORTH);
    instanceSet.add(instanceListView, BorderLayout.CENTER);
    instanceSet.add(new JLabel(GT._("double-click and drag to reorder")),
        BorderLayout.SOUTH);

    //Create the Instance add button.
    addInstanceButton = new JButton(GT._("Add Present Jmol State as Instance..."));
    addInstanceButton.addActionListener(this);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setMaximumSize(new Dimension(350, 50));
    showInstanceButton = new JButton(GT._("Show Selected"));
    showInstanceButton.addActionListener(this);
    deleteInstanceButton = new JButton(GT._("Delete Selected"));
    deleteInstanceButton.addActionListener(this);
    buttonPanel.add(showInstanceButton);
    buttonPanel.add(deleteInstanceButton);

    // width height or %width

    JPanel paramPanel = appletParamPanel();
    paramPanel.setMaximumSize(new Dimension(350, 70));

    //Instance selection
    JPanel instanceButtonPanel = new JPanel();
    instanceButtonPanel.add(addInstanceButton);
    instanceButtonPanel.setSize(300, 70);

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(instanceButtonPanel, BorderLayout.NORTH);
    p.add(buttonPanel, BorderLayout.SOUTH);

    JPanel instancePanel = new JPanel();
    instancePanel.setLayout(new BorderLayout());
    instancePanel.add(instanceSet, BorderLayout.CENTER);
    instancePanel.add(p, BorderLayout.SOUTH);

    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.setMinimumSize(new Dimension(350, 350));
    rightPanel.setMaximumSize(new Dimension(350, 1000));
    rightPanel.add(paramPanel, BorderLayout.NORTH);
    rightPanel.add(instancePanel, BorderLayout.CENTER);
    rightPanel.setBorder(BorderFactory.createTitledBorder(GT._("Jmol Instances:")));

    //Create the overall panel
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    JPanel leftPanel = getLeftPanel(infoWidth, infoHeight);
    leftPanel.setMaximumSize(new Dimension(350, 1000));

  
    //Add everything to this panel.
    panel.add(leftPanel, BorderLayout.CENTER);
    panel.add(rightPanel, BorderLayout.EAST);

    enableButtons(instanceList);
    return panel;
  }
Example #11
0
    @Override
    public void addGui(PreferenceTabbedPane gui) {
      actionsTree.setCellRenderer(
          new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(
                JTree tree,
                Object value,
                boolean sel,
                boolean expanded,
                boolean leaf,
                int row,
                boolean hasFocus) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              JLabel comp =
                  (JLabel)
                      super.getTreeCellRendererComponent(
                          tree, value, sel, expanded, leaf, row, hasFocus);
              if (node.getUserObject() == null) {
                comp.setText(tr("Separator"));
                comp.setIcon(ImageProvider.get("preferences/separator"));
              } else if (node.getUserObject() instanceof Action) {
                Action action = (Action) node.getUserObject();
                comp.setText((String) action.getValue(Action.NAME));
                comp.setIcon((Icon) action.getValue(Action.SMALL_ICON));
              }
              return comp;
            }
          });

      ListCellRenderer renderer =
          new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(
                JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              String s;
              Icon i;
              ActionDefinition action = (ActionDefinition) value;
              if (!action.isSeparator()) {
                s = action.getDisplayName();
                i = action.getDisplayIcon();
              } else {
                i = ImageProvider.get("preferences/separator");
                s = tr("Separator");
              }
              JLabel l =
                  (JLabel)
                      super.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus);
              l.setIcon(i);
              return l;
            }
          };
      selectedList.setCellRenderer(renderer);
      selectedList.addListSelectionListener(
          new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
              boolean sel = selectedList.getSelectedIndex() != -1;
              if (sel) {
                actionsTree.clearSelection();
                ActionDefinition action =
                    (ActionDefinition) selected.get(selectedList.getSelectedIndex());
                actionParametersModel.setCurrentAction(action);
                actionParametersPanel.setVisible(actionParametersModel.getRowCount() > 0);
              }
              updateEnabledState();
            }
          });

      selectedList.setDragEnabled(true);
      selectedList.setTransferHandler(
          new TransferHandler() {
            @Override
            protected Transferable createTransferable(JComponent c) {
              List<ActionDefinition> actions = new ArrayList<ActionDefinition>();
              for (Object o : ((JList) c).getSelectedValues()) {
                actions.add((ActionDefinition) o);
              }
              return new ActionTransferable(actions);
            }

            @Override
            public int getSourceActions(JComponent c) {
              return TransferHandler.MOVE;
            }

            @Override
            public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
              for (DataFlavor f : transferFlavors) {
                if (ACTION_FLAVOR.equals(f)) return true;
              }
              return false;
            }

            @Override
            public void exportAsDrag(JComponent comp, InputEvent e, int action) {
              super.exportAsDrag(comp, e, action);
              movingComponent = "list";
            }

            @Override
            public boolean importData(JComponent comp, Transferable t) {
              try {
                int dropIndex = selectedList.locationToIndex(selectedList.getMousePosition(true));
                List<?> draggedData = (List<?>) t.getTransferData(ACTION_FLAVOR);

                Object leadItem = dropIndex >= 0 ? selected.elementAt(dropIndex) : null;
                int dataLength = draggedData.size();

                if (leadItem != null) {
                  for (Object o : draggedData) {
                    if (leadItem.equals(o)) return false;
                  }
                }

                int dragLeadIndex = -1;
                boolean localDrop = "list".equals(movingComponent);

                if (localDrop) {
                  dragLeadIndex = selected.indexOf(draggedData.get(0));
                  for (Object o : draggedData) {
                    selected.removeElement(o);
                  }
                }
                int[] indices = new int[dataLength];

                if (localDrop) {
                  int adjustedLeadIndex = selected.indexOf(leadItem);
                  int insertionAdjustment = dragLeadIndex <= adjustedLeadIndex ? 1 : 0;
                  for (int i = 0; i < dataLength; i++) {
                    selected.insertElementAt(
                        draggedData.get(i), adjustedLeadIndex + insertionAdjustment + i);
                    indices[i] = adjustedLeadIndex + insertionAdjustment + i;
                  }
                } else {
                  for (int i = 0; i < dataLength; i++) {
                    selected.add(dropIndex, draggedData.get(i));
                    indices[i] = dropIndex + i;
                  }
                }
                selectedList.clearSelection();
                selectedList.setSelectedIndices(indices);
                movingComponent = "";
                return true;
              } catch (Exception e) {
                e.printStackTrace();
              }
              return false;
            }

            @Override
            protected void exportDone(JComponent source, Transferable data, int action) {
              if (movingComponent.equals("list")) {
                try {
                  List<?> draggedData = (List<?>) data.getTransferData(ACTION_FLAVOR);
                  boolean localDrop = selected.contains(draggedData.get(0));
                  if (localDrop) {
                    int[] indices = selectedList.getSelectedIndices();
                    Arrays.sort(indices);
                    for (int i = indices.length - 1; i >= 0; i--) {
                      selected.remove(indices[i]);
                    }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
                movingComponent = "";
              }
            }
          });

      actionsTree.setTransferHandler(
          new TransferHandler() {
            private static final long serialVersionUID = 1L;

            @Override
            public int getSourceActions(JComponent c) {
              return TransferHandler.MOVE;
            }

            @Override
            protected void exportDone(JComponent source, Transferable data, int action) {}

            @Override
            protected Transferable createTransferable(JComponent c) {
              TreePath[] paths = actionsTree.getSelectionPaths();
              List<ActionDefinition> dragActions = new ArrayList<ActionDefinition>();
              for (TreePath path : paths) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object obj = node.getUserObject();
                if (obj == null) {
                  dragActions.add(ActionDefinition.getSeparator());
                } else if (obj instanceof Action) {
                  dragActions.add(new ActionDefinition((Action) obj));
                }
              }
              return new ActionTransferable(dragActions);
            }
          });
      actionsTree.setDragEnabled(true);
      actionsTree
          .getSelectionModel()
          .addTreeSelectionListener(
              new TreeSelectionListener() {
                @Override
                public void valueChanged(TreeSelectionEvent e) {
                  updateEnabledState();
                }
              });

      final JPanel left = new JPanel(new GridBagLayout());
      left.add(new JLabel(tr("Toolbar")), GBC.eol());
      left.add(new JScrollPane(selectedList), GBC.std().fill(GBC.BOTH));

      final JPanel right = new JPanel(new GridBagLayout());
      right.add(new JLabel(tr("Available")), GBC.eol());
      right.add(new JScrollPane(actionsTree), GBC.eol().fill(GBC.BOTH));

      final JPanel buttons = new JPanel(new GridLayout(6, 1));
      buttons.add(upButton = createButton("up"));
      buttons.add(addButton = createButton("<"));
      buttons.add(removeButton = createButton(">"));
      buttons.add(downButton = createButton("down"));
      updateEnabledState();

      final JPanel p = new JPanel();
      p.setLayout(
          new LayoutManager() {
            @Override
            public void addLayoutComponent(String name, Component comp) {}

            @Override
            public void removeLayoutComponent(Component comp) {}

            @Override
            public Dimension minimumLayoutSize(Container parent) {
              Dimension l = left.getMinimumSize();
              Dimension r = right.getMinimumSize();
              Dimension b = buttons.getMinimumSize();
              return new Dimension(
                  l.width + b.width + 10 + r.width, l.height + b.height + 10 + r.height);
            }

            @Override
            public Dimension preferredLayoutSize(Container parent) {
              Dimension l = new Dimension(200, 200); // left.getPreferredSize();
              Dimension r = new Dimension(200, 200); // right.getPreferredSize();
              return new Dimension(
                  l.width + r.width + 10 + buttons.getPreferredSize().width,
                  Math.max(l.height, r.height));
            }

            @Override
            public void layoutContainer(Container parent) {
              Dimension d = p.getSize();
              Dimension b = buttons.getPreferredSize();
              int width = (d.width - 10 - b.width) / 2;
              left.setBounds(new Rectangle(0, 0, width, d.height));
              right.setBounds(new Rectangle(width + 10 + b.width, 0, width, d.height));
              buttons.setBounds(
                  new Rectangle(width + 5, d.height / 2 - b.height / 2, b.width, b.height));
            }
          });
      p.add(left);
      p.add(buttons);
      p.add(right);

      actionParametersPanel = new JPanel(new GridBagLayout());
      actionParametersPanel.add(
          new JLabel(tr("Action parameters")), GBC.eol().insets(0, 10, 0, 20));
      actionParametersTable.getColumnModel().getColumn(0).setHeaderValue(tr("Parameter name"));
      actionParametersTable.getColumnModel().getColumn(1).setHeaderValue(tr("Parameter value"));
      actionParametersPanel.add(
          actionParametersTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
      actionParametersPanel.add(
          actionParametersTable, GBC.eol().fill(GBC.BOTH).insets(0, 0, 0, 10));
      actionParametersPanel.setVisible(false);

      JPanel panel = gui.createPreferenceTab(this);
      panel.add(p, GBC.eol().fill(GBC.BOTH));
      panel.add(actionParametersPanel, GBC.eol().fill(GBC.HORIZONTAL));
      selected.removeAllElements();
      for (ActionDefinition actionDefinition : getDefinedActions()) {
        selected.addElement(actionDefinition);
      }
    }
  private void setupList() {
    _listMouseObserver = new LibraryPlaylistsMouseObserver();
    _listSelectionListener = new LibraryPlaylistsSelectionListener();

    SortedListModel sortedModel =
        new SortedListModel(
            _model,
            SortOrder.ASCENDING,
            new Comparator<LibraryPlaylistsListCell>() {

              @Override
              public int compare(LibraryPlaylistsListCell o1, LibraryPlaylistsListCell o2) {
                if (o1 == _newPlaylistCell) {
                  return -1;
                }
                if (o2 == _newPlaylistCell) {
                  return 1;
                }

                return o1.getText().compareTo(o2.getText());
              }
            });

    _list = new LibraryIconList(sortedModel);
    _list.setFixedCellHeight(TableSettings.DEFAULT_TABLE_ROW_HEIGHT.getValue());
    _list.setCellRenderer(new LibraryPlaylistsCellRenderer());
    _list.addMouseListener(new DefaultMouseListener(_listMouseObserver));
    _list.addListSelectionListener(_listSelectionListener);
    _list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    _list.setLayoutOrientation(JList.VERTICAL);
    _list.setPrototypeCellValue(
        new LibraryPlaylistsListCell(
            "test", "", GUIMediator.getThemeImage("playlist"), null, null));
    _list.setVisibleRowCount(-1);
    _list.setDragEnabled(true);
    _list.setTransferHandler(new LibraryPlaylistsTransferHandler(_list));
    ToolTipManager.sharedInstance().registerComponent(_list);

    _list.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            list_keyPressed(e);
          }
        });

    _list.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
              actionStartRename();
            }
          }
        });

    _textName = new JTextField();
    ThemeMediator.fixKeyStrokes(_textName);
    UIDefaults defaults = new UIDefaults();
    defaults.put("TextField.contentMargins", new InsetsUIResource(0, 4, 0, 4));
    _textName.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    _textName.putClientProperty("Nimbus.Overrides", defaults);
    _textName.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            textName_keyPressed(e);
          }
        });
    _textName.setVisible(false);

    _list.add(_textName);
  }
  @Override
  public JComponent createDialogContent() {
    mDialogPanel = new JPanel();
    double[][] size = {
      {8, TableLayout.PREFERRED, 4, TableLayout.PREFERRED, 8},
      {
        8,
        TableLayout.PREFERRED,
        16,
        TableLayout.PREFERRED,
        16,
        TableLayout.PREFERRED,
        8,
        TableLayout.PREFERRED,
        4,
        TableLayout.PREFERRED,
        12,
        TableLayout.PREFERRED,
        4,
        TableLayout.PREFERRED,
        8
      }
    };
    mDialogPanel.setLayout(new TableLayout(size));

    if (mDefaultColumn == -1) {
      mComboBoxColumn = new JComboBox();
      for (int column = 0; column < mTableModel.getTotalColumnCount(); column++)
        if (columnQualifies(mTableModel, column))
          mComboBoxColumn.addItem(mTableModel.getColumnTitle(column));
      mComboBoxColumn.addActionListener(this);
      mComboBoxColumn.setEditable(mDefaultColumn == -1);
      mDialogPanel.add(new JLabel("Column:"), "1,1");
      mDialogPanel.add(mComboBoxColumn, "3,1");
    }

    mRadioButton = new JRadioButton("Use custom order");
    mRadioButton.addActionListener(this);
    mDialogPanel.add(mRadioButton, "1,3,3,3");

    mDialogPanel.add(new JLabel("Define order of category items:"), "1,5,3,5");

    if (mDefaultColumn != -1) {
      mListModel = new DefaultListModel();
      mList = new JList(mListModel);
      mList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
      mList.setDropMode(DropMode.INSERT);
      mList.setTransferHandler(new ListTransferHandler());
      mList.setDragEnabled(true);
      mList
          .getModel()
          .addListDataListener(
              new ListDataListener() {
                @Override
                public void intervalAdded(ListDataEvent e) {
                  mActiveSortMode = -1;
                }

                @Override
                public void intervalRemoved(ListDataEvent e) {
                  mActiveSortMode = -1;
                }

                @Override
                public void contentsChanged(ListDataEvent e) {
                  mActiveSortMode = -1;
                }
              });

      mScrollPane = new JScrollPane(mList);
      int height =
          Math.max(
              240,
              Math.min(
                  640,
                  (1 + mTableModel.getCategoryCount(mDefaultColumn))
                      * ((mTableModel.getColumnSpecialType(mDefaultColumn) == null) ? 20 : 80)));
      mScrollPane.setPreferredSize(new Dimension(240, height));
    } else {
      mTextArea = new JTextArea();
      mScrollPane = new JScrollPane(mTextArea);
      mScrollPane.setPreferredSize(new Dimension(240, 240));
      mIsStructure = false;
    }

    mDialogPanel.add(mScrollPane, "1,7,3,7");

    if (mDefaultColumn == -1) {
      mRadioButtonIsStructure = new JRadioButton("Column contains chemical structures");
      mRadioButtonIsStructure.addActionListener(this);
      mDialogPanel.add(mRadioButtonIsStructure, "1,9,3,9");
    }

    if (mDefaultColumn != -1) {
      mButtonSort = new JButton("Sort categories");
      mButtonSort.addActionListener(this);
      mDialogPanel.add(mButtonSort, "1,11");
    } else {
      mRadioButtonSort = new JRadioButton("Sort Categories");
      mRadioButtonSort.addActionListener(this);
      mDialogPanel.add(mRadioButtonSort, "1,11");
    }
    mComboBoxSortOrder = new JComboBox(SORT_ORDER_NAME);
    mDialogPanel.add(mComboBoxSortOrder, "3,11");

    mComboBoxSortMode = new JComboBox(SORT_MODE_NAME);
    mComboBoxSortMode.addActionListener(this);
    mDialogPanel.add(mComboBoxSortMode, "1,13");

    mComboBoxSortColumn = new JComboBox();
    for (int column = 0; column < mTableModel.getTotalColumnCount(); column++)
      if (columnQualifiesAsSortColumn(mTableModel, column))
        mComboBoxSortColumn.addItem(mTableModel.getColumnTitle(column));
    mComboBoxSortColumn.addActionListener(this);
    mComboBoxSortColumn.setEditable(mDefaultColumn == -1);
    mDialogPanel.add(mComboBoxSortColumn, "3,13");

    return mDialogPanel;
  }