List of usage examples for javax.swing Box createVerticalBox
public static Box createVerticalBox()
Box
that displays its components from top to bottom. From source file:com.t3.macro.api.functions.input.ColumnPanel.java
/** Creates a group of radio buttons. */ public JComponent createRadioControl(VarSpec vs) { int listIndex = vs.optionValues.getNumeric("SELECT"); if (listIndex < 0 || listIndex >= vs.valueList.size()) listIndex = 0;/*from w w w . java 2 s . c o m*/ ButtonGroup bg = new ButtonGroup(); Box box = (vs.optionValues.optionEquals("ORIENT", "H")) ? Box.createHorizontalBox() : Box.createVerticalBox(); // If the prompt is suppressed by SPAN=TRUE, use it as the border title String title = ""; if (vs.optionValues.optionEquals("SPAN", "TRUE")) title = vs.prompt; box.setBorder(new TitledBorder(new EtchedBorder(), title)); int radioCount = 0; for (String value : vs.valueList) { JRadioButton radio = new JRadioButton(value, false); bg.add(radio); box.add(radio); if (listIndex == radioCount) radio.setSelected(true); radioCount++; } return box; }
From source file:cloud.gui.CloudGUI.java
private JPanel createCurrentInstancesPanel() { JPanel currentInstancesPanel = new JPanel(); currentInstancesPanel.setBorder(BorderFactory.createTitledBorder("Current Instances")); currentInstancesPanel.setLayout(new BoxLayout(currentInstancesPanel, BoxLayout.Y_AXIS)); Box layout = Box.createVerticalBox(); createNumberOfInstancesStatus(layout); createTotalCost(layout);//from ww w . ja v a 2 s . com createInstanceTable(layout); removeInstanceButton = new JButton("Remove instance"); layout.add(removeInstanceButton); currentInstancesPanel.add(layout); return currentInstancesPanel; }
From source file:de.adv_online.aaa.katalogtool.KatalogDialog.java
public void initialise(Converter c, Options o, ShapeChangeResult r, String mdl) throws ShapeChangeAbortException { try {/*from w w w.j ava 2 s . c o m*/ String msg = "Akzeptieren Sie die in der mit diesem Tool ausgelieferten Datei 'Lizenzbedingungen zur Nutzung von Softwareskripten.doc' beschriebenen Lizenzbedingungen?"; // Meldung if (msg != null) { Object[] options = { "Ja", "Nein" }; int val = JOptionPane.showOptionDialog(null, msg, "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (val == 1) System.exit(0); } } catch (Exception e) { System.out.println("Fehler in Dialog: " + e.toString()); } options = o; File eapFile = new File(mdl); try { eap = eapFile.getCanonicalFile().getAbsolutePath(); } catch (IOException e) { eap = "ERROR.eap"; } converter = new Converter(options, r); result = r; modelTransformed = false; transformationRunning = false; StatusBoard.getStatusBoard().registerStatusReader(this); // frame setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // panel newContentPane = new JPanel(new BorderLayout()); newContentPane.setOpaque(true); setContentPane(newContentPane); // target elements for (String label : targetLabels) { try { TargetGuiElements t = new TargetGuiElements(this, label); targetGuiElems.put(label, t); } catch (Exception e) { throw new ShapeChangeAbortException("Fatal error while creating dialog elements for target " + label + ".\nMessage: " + eap.toString() + "\nPlease check configuration file."); } } //JTabbedPane tabbedPane = new JTabbedPane(); //tabbedPane.addTab("Main options", createMainTab()); newContentPane.add(createMainTab(), BorderLayout.CENTER); statusBar = new StatusBar(); Box fileBox = Box.createVerticalBox(); fileBox.add(createStartPanel()); fileBox.add(statusBar); newContentPane.add(fileBox, BorderLayout.SOUTH); // frame size int height = 720; int width = 600; pack(); Insets fI = getInsets(); setSize(width + fI.right + fI.left, height + fI.top + fI.bottom); Dimension sD = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((sD.width - width) / 2, (sD.height - height) / 2); this.setMinimumSize(new Dimension(width, height)); // frame closing WindowListener listener = new WindowAdapter() { public void windowClosing(WindowEvent w) { //JOptionPane.showMessageDialog(null, "Nein", "NO", JOptionPane.ERROR_MESSAGE); closeDialog(); } }; addWindowListener(listener); }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * Build content for animationType StatisticGrafic.ANIMATION_LastValue * @return/*from ww w . j a v a 2 s .c o m*/ */ private JPanel buildLastValuePanel() { JPanel out = new JPanel(); out.setBackground(Grafic.COLOR_BACKGROUND); out.setOpaque(true); out.setLayout(new BorderLayout()); switch (this.statistic.getTypeIndex()) { case Statistic.INDEX_None: this.valueLabel = new JLabel(); this.valueLabel.setFont(Grafic.FONT_BIG); this.valueLabel.setForeground(Grafic.COLOR_FOREGROUND); out.add(this.valueLabel, BorderLayout.CENTER); if (this.isIntValue) out.setPreferredSize(new Dimension(80, 50)); else out.setPreferredSize(new Dimension(100, 50)); break; case Statistic.INDEX_Min_Max: this.valueLabel = new JLabel(); this.valueLabel.setFont(Grafic.FONT_BIG); this.valueLabel.setForeground(Grafic.COLOR_FOREGROUND); out.add(this.valueLabel, BorderLayout.CENTER); ; Box top = Box.createVerticalBox(); this.minLabel = new JLabel(); this.minLabel.setFont(Grafic.FONT_DEFAULT); this.minLabel.setForeground(Grafic.COLOR_FOREGROUND); top.add(this.minLabel); this.maxLabel = new JLabel(); this.maxLabel.setFont(Grafic.FONT_DEFAULT); this.maxLabel.setForeground(Grafic.COLOR_FOREGROUND); top.add(this.maxLabel); out.add(top, BorderLayout.SOUTH); if (this.isIntValue) out.setPreferredSize(new Dimension(80, 70)); else out.setPreferredSize(new Dimension(100, 70)); break; case Statistic.INDEX_Mean_StdDev: this.valueLabel = new JLabel(); this.valueLabel.setFont(Grafic.FONT_BIG); this.valueLabel.setForeground(Grafic.COLOR_FOREGROUND); out.add(this.valueLabel, BorderLayout.CENTER); ; Box bottom = Box.createVerticalBox(); this.meanLabel = new JLabel(); this.meanLabel.setFont(Grafic.FONT_DEFAULT); this.meanLabel.setForeground(Grafic.COLOR_FOREGROUND); bottom.add(this.meanLabel); this.stdDevLabel = new JLabel(); this.stdDevLabel.setFont(Grafic.FONT_DEFAULT); this.stdDevLabel.setForeground(Grafic.COLOR_FOREGROUND); bottom.add(this.stdDevLabel); out.add(bottom, BorderLayout.SOUTH); if (this.isIntValue) out.setPreferredSize(new Dimension(80, 70)); else out.setPreferredSize(new Dimension(100, 70)); break; } return out; }
From source file:cellularAutomata.analysis.PricingDistributionAnalysis.java
/** * Create the panel used to display the pricing statistics. *//*www .ja v a 2 s. co m*/ private void createDisplayPanel() { int displayWidth = CAFrame.tabbedPaneDimension.width; int displayHeight = 600 + (100 * numberOfStates); // create the display panel if (displayPanel == null) { displayPanel = new JPanel(new GridBagLayout()); displayPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); displayPanel.setPreferredSize(new Dimension(displayWidth, displayHeight)); } else { displayPanel.removeAll(); } if (isCompatibleRule && (numberOfStates <= MAX_NUMBER_OF_STATES)) { // create a panel that displays messages JPanel messagePanel = createMessagePanel(); // create the labels for the display createDataDisplayLabels(); JLabel generationLabel = new JLabel("Generation: "); JLabel stateLabel = new JLabel("State:"); JLabel numStateLabel = new JLabel("Number:"); JLabel percentOccupiedLabel = new JLabel("Kurtosis:"); // create boxes for each column of the display (a Box uses the // BoxLayout, so it is handy for laying out components) Box boxOfStateLabels = Box.createVerticalBox(); Box boxOfNumberLabels = Box.createVerticalBox(); Box boxOfPercentLabels = Box.createVerticalBox(); // the amount of vertical space to put between components int verticalSpace = 5; // add the states to the first vertical box boxOfStateLabels.add(stateLabel); boxOfStateLabels.add(Box.createVerticalStrut(verticalSpace)); for (int state = 0; state < numberOfStates; state++) { boxOfStateLabels.add(new JLabel("" + state)); boxOfStateLabels.add(Box.createVerticalStrut(verticalSpace)); } // add the numbers (in each state) to the second vertical box boxOfNumberLabels.add(numStateLabel); boxOfNumberLabels.add(Box.createVerticalStrut(verticalSpace)); for (int i = 0; i < numberOfStates; i++) { boxOfNumberLabels.add(numberOccupiedByStateDataLabel[i]); boxOfNumberLabels.add(Box.createVerticalStrut(verticalSpace)); } // add the percents (in each state) to the third vertical box boxOfPercentLabels.add(percentOccupiedLabel); boxOfPercentLabels.add(Box.createVerticalStrut(verticalSpace)); for (int i = 0; i < numberOfStates; i++) { boxOfPercentLabels.add(percentOccupiedByStateDataLabel[i]); boxOfPercentLabels.add(Box.createVerticalStrut(verticalSpace)); } // create another box that holds all of the label boxes Box boxOfLabels = Box.createHorizontalBox(); boxOfLabels.add(boxOfStateLabels); boxOfLabels.add(boxOfNumberLabels); boxOfLabels.add(boxOfPercentLabels); boxOfLabels.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); // put the boxOfLabels in a scrollPane -- with many states, will get // very large JScrollPane stateScroller = new JScrollPane(boxOfLabels); int scrollPaneWidth = (int) (displayWidth * 0.8); int scrollPaneHeight = displayHeight / 4; stateScroller.setPreferredSize(new Dimension(scrollPaneWidth, scrollPaneHeight)); stateScroller.setMinimumSize(new Dimension(scrollPaneWidth, scrollPaneHeight)); stateScroller.setMaximumSize(new Dimension(scrollPaneWidth, scrollPaneHeight)); stateScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // create a "plot zero state" check box plotZeroStateCheckBox = new JCheckBox(PLOT_ZERO_STATE); plotZeroStateCheckBox.setSelected(true); plotZeroStateCheckBox.setToolTipText(PLOT_ZERO_STATE_TOOLTIP); plotZeroStateCheckBox.setActionCommand(PLOT_ZERO_STATE); plotZeroStateCheckBox.addActionListener(this); JPanel plotZeroStatePanel = new JPanel(new BorderLayout()); plotZeroStatePanel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); plotZeroStatePanel.add(BorderLayout.CENTER, plotZeroStateCheckBox); // create a "save data" check box saveDataCheckBox = new JCheckBox(SAVE_DATA); saveDataCheckBox.setToolTipText(SAVE_DATA_TOOLTIP); saveDataCheckBox.setActionCommand(SAVE_DATA); saveDataCheckBox.addActionListener(this); JPanel saveDataPanel = new JPanel(new BorderLayout()); saveDataPanel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); saveDataPanel.add(BorderLayout.CENTER, saveDataCheckBox); // create a panel that plots the data plot = new SimplePlot(); // add all the components to the panel int row = 0; displayPanel.add(messagePanel, new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH).setWeight(1.0, 1.0) .setAnchor(GBC.WEST).setInsets(1)); row++; displayPanel.add(plot, new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH).setWeight(10.0, 10.0) .setAnchor(GBC.WEST).setInsets(1)); row++; for (int i = 0; i < numberOfStates; i++) { timeSeriesPlot[i] = new SimplePlot(); displayPanel.add(timeSeriesPlot[i], new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH) .setWeight(10.0, 10.0).setAnchor(GBC.WEST).setInsets(1)); row++; } displayPanel.add(plotZeroStatePanel, new GBC(1, row).setSpan(4, 1).setFill(GBC.NONE).setWeight(1.0, 1.0) .setAnchor(GBC.CENTER).setInsets(1)); row++; displayPanel.add(generationLabel, new GBC(1, row).setSpan(1, 1).setFill(GBC.NONE).setWeight(1.0, 1.0) .setAnchor(GBC.EAST).setInsets(1)); displayPanel.add(generationDataLabel, new GBC(2, row).setSpan(1, 1).setFill(GBC.NONE) .setWeight(1.0, 1.0).setAnchor(GBC.WEST).setInsets(1)); row++; displayPanel.add(stateScroller, new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH).setWeight(1.0, 1.0) .setAnchor(GBC.WEST).setInsets(1)); row++; displayPanel.add(saveDataPanel, new GBC(1, row).setSpan(4, 1).setFill(GBC.NONE).setWeight(1.0, 1.0) .setAnchor(GBC.CENTER).setInsets(1)); } else { int row = 0; displayPanel.add(createWarningMessagePanel(), new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH) .setWeight(1.0, 1.0).setAnchor(GBC.WEST).setInsets(1)); } }
From source file:de.adv_online.aaa.profiltool.ProfilDialog.java
private Component createMainTab() { String s;//from ww w. j a v a2 s . c om String appSchemaStr; s = options.parameter("appSchemaName"); if (s != null && s.trim().length() > 0) appSchemaStr = s.trim(); else appSchemaStr = ""; String mart; s = options.parameter(paramProfilClass, "Modellart"); if (s != null && s.trim().length() > 0) mart = s.trim(); else mart = ""; String profil; s = options.parameter(paramProfilClass, "Profil"); if (s != null && s.trim().length() > 0) profil = s.trim(); else profil = ""; String quelle; s = options.parameter(paramProfilClass, "Quelle"); if (s != null && s.trim().length() > 0) quelle = s.trim(); else quelle = "Neu_Minimal"; String ziel; s = options.parameter(paramProfilClass, "Ziel"); if (s != null && s.trim().length() > 0) ziel = s.trim(); else ziel = "Datei"; String pfadStr; s = options.parameter(paramProfilClass, "Verzeichnis"); if (s == null || s.trim().length() == 0) pfadStr = ""; else { File f = new File(s.trim()); if (f.exists()) pfadStr = f.getAbsolutePath(); else pfadStr = ""; } String mdlDirStr = eap; final JPanel topPanel = new JPanel(); final JPanel topInnerPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 30, 5)); topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS)); topPanel.setBorder(BorderFactory.createEmptyBorder(15, 20, 15, 10)); // Anwendungsschema appSchemaField = new JTextField(35); appSchemaField.setText(appSchemaStr); appSchemaFieldLabel = new JLabel("Name des zu prozessierenden Anwendungsschemas:"); Box asBox = Box.createVerticalBox(); asBox.add(appSchemaFieldLabel); asBox.add(appSchemaField); modellartField = new JTextField(10); modellartField.setText(mart); modellartFieldLabel = new JLabel("Modellart:"); asBox.add(modellartFieldLabel); asBox.add(modellartField); profilField = new JTextField(10); profilField.setText(profil); profilFieldLabel = new JLabel("Profilkennung:"); asBox.add(profilFieldLabel); asBox.add(profilField); topInnerPanel.add(asBox); topPanel.add(topInnerPanel); // Quelle Box quelleBox = Box.createVerticalBox(); final JPanel quellePanel = new JPanel(new GridLayout(4, 1)); quelleGroup = new ButtonGroup(); rbq3ap = new JRadioButton("3ap-Datei"); quellePanel.add(rbq3ap); if (quelle.equals("Datei")) rbq3ap.setSelected(true); rbq3ap.setActionCommand("Datei"); quelleGroup.add(rbq3ap); rbqtv = new JRadioButton("'AAA:Profile' Tagged Values in Modell"); quellePanel.add(rbqtv); if (quelle.equals("Modell")) rbqtv.setSelected(true); rbqtv.setActionCommand("Modell"); quelleGroup.add(rbqtv); rbqmin = new JRadioButton("Neues Minimalprofil erzeugen"); quellePanel.add(rbqmin); if (quelle.equals("Neu_Minimal")) rbqmin.setSelected(true); rbqmin.setActionCommand("Neu_Minimal"); quelleGroup.add(rbqmin); rbqmax = new JRadioButton("Neues Maximalprofil erzeugen"); quellePanel.add(rbqmax); if (quelle.equals("Neu_Maximal")) rbqmax.setSelected(true); rbqmax.setActionCommand("Neu_Maximal"); quelleGroup.add(rbqmax); quelleBorder = new TitledBorder(new LineBorder(Color.black), "Quelle der Profildefinition", TitledBorder.LEFT, TitledBorder.TOP); quellePanel.setBorder(quelleBorder); quelleBox.add(quellePanel); Box zielBox = Box.createVerticalBox(); final JPanel zielPanel = new JPanel(new GridLayout(4, 1)); zielGroup = new ButtonGroup(); rbz3ap = new JRadioButton("3ap-Datei"); zielPanel.add(rbz3ap); if (ziel.equals("Datei")) rbz3ap.setSelected(true); rbz3ap.setActionCommand("Datei"); zielGroup.add(rbz3ap); rbztv = new JRadioButton("'AAA:Profile' Tagged Values in Modell"); zielPanel.add(rbztv); if (ziel.equals("Modell")) rbztv.setSelected(true); rbztv.setActionCommand("Modell"); zielGroup.add(rbztv); rbzbeide = new JRadioButton("Beides"); zielPanel.add(rbzbeide); if (ziel.equals("DateiModell")) rbzbeide.setSelected(true); rbzbeide.setActionCommand("DateiModell"); zielGroup.add(rbzbeide); rbzdel = new JRadioButton("Profilkennung wird aus Modell entfernt"); zielPanel.add(rbzdel); if (ziel.equals("Ohne")) rbzdel.setSelected(true); rbzdel.setActionCommand("Ohne"); zielGroup.add(rbzdel); zielBorder = new TitledBorder(new LineBorder(Color.black), "Ziel der Profildefinition", TitledBorder.LEFT, TitledBorder.TOP); zielPanel.setBorder(zielBorder); zielBox.add(zielPanel); // Pfadangaben Box pfadBox = Box.createVerticalBox(); final JPanel pfadInnerPanel = new JPanel(); Box skBox = Box.createVerticalBox(); pfadFieldLabel = new JLabel("Pfad in dem 3ap-Dateien liegen/geschrieben werden:"); skBox.add(pfadFieldLabel); pfadField = new JTextField(40); pfadField.setText(pfadStr); skBox.add(pfadField); mdlDirFieldLabel = new JLabel("Pfad zum Modell:"); skBox.add(mdlDirFieldLabel); mdlDirField = new JTextField(40); mdlDirField.setText(mdlDirStr); skBox.add(mdlDirField); pfadInnerPanel.add(skBox); pfadBox.add(pfadInnerPanel); final JPanel pfadPanel = new JPanel(); pfadPanel.add(pfadBox); pfadPanel.setBorder( new TitledBorder(new LineBorder(Color.black), "Pfadangaben", TitledBorder.LEFT, TitledBorder.TOP)); // Zusammenstellung Box fileBox = Box.createVerticalBox(); fileBox.add(topPanel); fileBox.add(quellePanel); fileBox.add(zielPanel); fileBox.add(pfadPanel); JPanel panel = new JPanel(new BorderLayout()); panel.add(fileBox, BorderLayout.NORTH); if (profil.isEmpty()) { setModellartOnly = true; disableProfileElements(); } // Listen for changes in the profilkennung profilField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { upd(); } public void removeUpdate(DocumentEvent e) { upd(); } public void insertUpdate(DocumentEvent e) { upd(); } public void upd() { if (!setModellartOnly && profilField.getText().isEmpty()) { setModellartOnly = true; disableProfileElements(); } else if (setModellartOnly && !profilField.getText().isEmpty()) { setModellartOnly = false; enableProfileElements(); } } }); return panel; }
From source file:metdemo.Finance.Pluggable.java
protected void addBottomControls(final JPanel jp) { final JPanel control_panel = new JPanel(); jp.add(control_panel, BorderLayout.SOUTH); control_panel.setLayout(new BorderLayout()); final Box vertex_panel = Box.createVerticalBox(); vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices")); final Box edge_panel = Box.createVerticalBox(); edge_panel.setBorder(BorderFactory.createTitledBorder("Edges")); final Box both_panel = Box.createVerticalBox(); control_panel.add(vertex_panel, BorderLayout.WEST); control_panel.add(edge_panel, BorderLayout.EAST); control_panel.add(both_panel, BorderLayout.CENTER); // set up vertex controls v_color = new JCheckBox("vertex seed coloring"); v_color.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vcf.setSeedColoring(v_color.isSelected()); }/*from w w w. j a va2s .c om*/ }); v_stroke = new JCheckBox("<html>vertex selection<p>stroke highlighting</html>"); v_stroke.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vsh.setHighlight(v_stroke.isSelected()); } }); v_labels = new JCheckBox("show vertex ranks (voltages)"); v_labels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (v_labels.isSelected()) pr.setVertexStringer(vs); else pr.setVertexStringer(vs_none); } }); v_shape = new JCheckBox("vertex degree shapes"); v_shape.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vssa.useFunnyShapes(v_shape.isSelected()); } }); v_size = new JCheckBox("vertex voltage size"); v_size.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vssa.setScaling(v_size.isSelected()); } }); v_aspect = new JCheckBox("vertex degree ratio stretch"); v_aspect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vssa.setStretching(v_aspect.isSelected()); } }); v_small = new JCheckBox("filter vertices of degree < " + VertexDisplayPredicate.MIN_DEGREE); v_small.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { show_vertex.filterSmall(v_small.isSelected()); } }); vertex_panel.add(v_color); vertex_panel.add(v_stroke); vertex_panel.add(v_labels); vertex_panel.add(v_shape); vertex_panel.add(v_size); vertex_panel.add(v_aspect); vertex_panel.add(v_small); // set up edge controls JPanel gradient_panel = new JPanel(new GridLayout(1, 0)); gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint")); no_gradient = new JRadioButton("Solid color"); no_gradient.setSelected(true); no_gradient.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gradient_level = GRADIENT_NONE; } }); // gradient_absolute = new JRadioButton("Absolute gradient"); // gradient_absolute.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) { gradient_level = GRADIENT_ABSOLUTE;}}); gradient_relative = new JRadioButton("Gradient"); gradient_relative.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gradient_level = GRADIENT_RELATIVE; } }); ButtonGroup bg_grad = new ButtonGroup(); bg_grad.add(no_gradient); bg_grad.add(gradient_relative); //bg_grad.add(gradient_absolute); gradient_panel.add(no_gradient); //gradientGrid.add(gradient_absolute); gradient_panel.add(gradient_relative); JPanel shape_panel = new JPanel(new GridLayout(3, 2)); shape_panel.setBorder(BorderFactory.createTitledBorder("Edge shape")); e_line = new JRadioButton("line"); e_line.setSelected(true); e_line.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pr.setEdgeShapeFunction(new EdgeShape.Line()); } }); // e_bent = new JRadioButton("bent line"); // e_bent.setSelected(true); e_wedge = new JRadioButton("wedge"); e_wedge.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pr.setEdgeShapeFunction(new EdgeShape.Wedge(10)); } }); e_quad = new JRadioButton("quad curve"); e_quad.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pr.setEdgeShapeFunction(new EdgeShape.QuadCurve()); } }); e_cubic = new JRadioButton("cubic curve"); e_cubic.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pr.setEdgeShapeFunction(new EdgeShape.CubicCurve()); } }); ButtonGroup bg_shape = new ButtonGroup(); bg_shape.add(e_line); // bg.add(e_bent); bg_shape.add(e_wedge); bg_shape.add(e_quad); bg_shape.add(e_cubic); shape_panel.add(e_line); // shape_panel.add(e_bent); shape_panel.add(e_wedge); shape_panel.add(e_quad); shape_panel.add(e_cubic); fill_edges = new JCheckBox("fill edge shapes"); fill_edges.setSelected(false); fill_edges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { edgePaint.useFill(fill_edges.isSelected()); } }); shape_panel.add(fill_edges); shape_panel.setOpaque(true); e_color = new JCheckBox("edge weight highlighting"); e_color.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ewcs.setWeighted(e_color.isSelected()); } }); e_labels = new JCheckBox("show edge weights"); e_labels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e_labels.isSelected()) pr.setEdgeStringer(es); else pr.setEdgeStringer(es_none); } }); e_uarrow_pred = new JCheckBox("undirected"); e_uarrow_pred.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { show_arrow.showUndirected(e_uarrow_pred.isSelected()); } }); e_darrow_pred = new JCheckBox("directed"); e_darrow_pred.setSelected(true); e_darrow_pred.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { show_arrow.showDirected(e_darrow_pred.isSelected()); } }); JPanel arrow_panel = new JPanel(new GridLayout(1, 0)); arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows")); arrow_panel.add(e_uarrow_pred); arrow_panel.add(e_darrow_pred); e_show_d = new JCheckBox("directed"); e_show_d.setSelected(true); e_show_d.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { show_edge.showDirected(e_show_d.isSelected()); } }); e_show_u = new JCheckBox("undirected"); e_show_u.setSelected(true); e_show_u.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { show_edge.showUndirected(e_show_u.isSelected()); } }); JPanel show_edge_panel = new JPanel(new GridLayout(1, 0)); show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges")); show_edge_panel.add(e_show_u); show_edge_panel.add(e_show_d); shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(shape_panel); gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(gradient_panel); show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(show_edge_panel); arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(arrow_panel); e_color.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_color); e_labels.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_labels); // set up zoom controls zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>"); zoom_at_mouse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gm.setZoomAtMouse(zoom_at_mouse.isSelected()); } }); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // call listener in GraphMouse instead of manipulating vv scale directly // this is so the crossover from zoom to scale works with the buttons // as well as with the mouse wheel Dimension d = vv.getSize(); gm.mouseWheelMoved(new MouseWheelEvent(vv, MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, d.width / 2, d.height / 2, 1, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 1)); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // call listener in GraphMouse instead of manipulating vv scale directly // this is so the crossover from zoom to scale works with the buttons // as well as with the mouse wheel Dimension d = vv.getSize(); gm.mouseWheelMoved(new MouseWheelEvent(vv, MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, d.width / 2, d.height / 2, 1, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, -1)); } }); Box zoomPanel = Box.createVerticalBox(); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); plus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(plus); minus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(minus); zoom_at_mouse.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(zoom_at_mouse); // add font and zoom controls to center panel font = new JCheckBox("bold text"); font.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ff.setBold(font.isSelected()); } }); font.setAlignmentX(Component.CENTER_ALIGNMENT); both_panel.add(zoomPanel); both_panel.add(font); JComboBox modeBox = gm.getModeComboBox(); modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel modePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); both_panel.add(modePanel); }
From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java
public PreferencesDialog(final DownloaderGUI owner, Properties config) { super(owner, "Preferences", true); HttpClientParams params = new HttpClientParams(); params.setVersion(HttpVersion.HTTP_1_1); params.setSoTimeout(30000);/*from w w w . j ava 2s . com*/ client = new HttpClient(params); setProxy(ProxyCfg.parseConfig(config)); sample = new Deviation(); sample.setId(15972367L); sample.setTitle("Fella Promo"); sample.setArtist("devart"); sample.setImageDownloadUrl(DOWNLOAD_URL); sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL)); sample.setCollection(new Collection(1L, "MyCollect")); setLayout(new BorderLayout()); panes = new JTabbedPane(JTabbedPane.TOP); JPanel genPanel = new JPanel(); BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS); genPanel.setLayout(genLayout); panes.add("General", genPanel); JLabel userLabel = new JLabel("Username"); userLabel.setToolTipText("The username the account you want to download the favorites from."); userField = new JTextField(config.getProperty(Constants.USERNAME)); userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); userLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); userField.setAlignmentX(JLabel.LEFT_ALIGNMENT); userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2)); genPanel.add(userLabel); genPanel.add(userField); JPanel radioPanel = new JPanel(); BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS); radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT); radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5)); radioPanel.setLayout(radioLayout); JLabel searchLabel = new JLabel("Search for"); searchLabel .setToolTipText("Select what you want to download from that user: it favorites or it galleries."); searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId())); buttonGroup = new ButtonGroup(); for (final SEARCH search : SEARCH.values()) { JRadioButton radio = new JRadioButton(search.getLabel()); radio.setAlignmentX(JLabel.LEFT_ALIGNMENT); radio.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectedSearch = search; } }); buttonGroup.add(radio); radioPanel.add(radio); if (search.equals(selectedSearch)) { radio.setSelected(true); } } genPanel.add(radioPanel); final JTextField sampleField = new JTextField(""); sampleField.setEditable(false); JLabel locationLabel = new JLabel("Download location"); locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in."); JLabel legendsLabel = new JLabel( "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>"); legendsLabel.setToolTipText("An example of where a file will be downloaded to."); locationString = new StringBuilder(); locationField = new JTextField(config.getProperty(Constants.LOCATION)); locationField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } public void keyReleased(KeyEvent e) { File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample, sample.getImageFilename()); locationString.setLength(0); locationString.append(dest.getAbsolutePath()); sampleField.setText(locationString.toString()); if (useSameForMatureBox.isSelected()) { locationMatureString.setLength(0); locationMatureString.append(sampleField.getText()); locationMatureField.setText(locationField.getText()); } } public void keyTyped(KeyEvent e) { } }); locationField.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseExited(MouseEvent e) { sampleField.setText(locationString.toString()); } public void mouseEntered(MouseEvent e) { sampleField.setText(locationString.toString()); } public void mouseClicked(MouseEvent e) { } }); JLabel locationMatureLabel = new JLabel("Mature download location"); locationMatureLabel.setToolTipText( "The folder pattern where you want the file marked as 'Mature' to be downloaded in."); locationMatureString = new StringBuilder(); locationMatureField = new JTextField(config.getProperty(Constants.MATURE)); locationMatureField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } public void keyReleased(KeyEvent e) { File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample, sample.getImageFilename()); locationMatureString.setLength(0); locationMatureString.append(dest.getAbsolutePath()); sampleField.setText(locationMatureString.toString()); } public void keyTyped(KeyEvent e) { } }); locationMatureField.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseExited(MouseEvent e) { sampleField.setText(locationString.toString()); } public void mouseEntered(MouseEvent e) { sampleField.setText(locationMatureString.toString()); } public void mouseClicked(MouseEvent e) { } }); useSameForMatureBox = new JCheckBox("Use same location for mature deviation?"); useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText())); useSameForMatureBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (useSameForMatureBox.isSelected()) { locationMatureField.setEditable(false); locationMatureField.setText(locationField.getText()); locationMatureString.setLength(0); locationMatureString.append(locationString); } else { locationMatureField.setEditable(true); } } }); File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample, sample.getImageFilename()); sampleField.setText(dest.getAbsolutePath()); locationString.append(sampleField.getText()); dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample, sample.getImageFilename()); locationMatureString.append(dest.getAbsolutePath()); locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2)); locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationMatureField .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2)); useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT); legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2)); sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT); sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2)); genPanel.add(locationLabel); genPanel.add(locationField); genPanel.add(locationMatureLabel); genPanel.add(locationMatureField); genPanel.add(useSameForMatureBox); genPanel.add(legendsLabel); genPanel.add(sampleField); genPanel.add(Box.createVerticalBox()); final KeyListener prxChangeListener = new KeyListener() { public void keyTyped(KeyEvent e) { proxyChangeState = true; } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } }; JPanel prxPanel = new JPanel(); BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS); prxPanel.setLayout(prxLayout); panes.add("Proxy", prxPanel); JLabel prxHostLabel = new JLabel("Proxy Host"); prxHostLabel.setToolTipText("The hostname of the proxy server"); prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST)); prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2)); JLabel prxPortLabel = new JLabel("Proxy Port"); prxPortLabel.setToolTipText("The port of the proxy server (Default 80)."); prxPortSpinner = new JSpinner(); prxPortSpinner.setModel(new SpinnerNumberModel( Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1)); prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2)); JLabel prxUserLabel = new JLabel("Proxy username"); prxUserLabel.setToolTipText("The username used for authentication, if applicable."); prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME)); prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2)); JLabel prxPassLabel = new JLabel("Proxy username"); prxPassLabel.setToolTipText("The username used for authentication, if applicable."); prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD)); prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2)); prxUseBox = new JCheckBox("Use a proxy?"); prxUseBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { prxChangeListener.keyTyped(null); if (prxUseBox.isSelected()) { prxHostField.setEditable(true); prxPortSpinner.setEnabled(true); prxUserField.setEditable(true); prxPassField.setEditable(true); } else { prxHostField.setEditable(false); prxPortSpinner.setEnabled(false); prxUserField.setEditable(false); prxPassField.setEditable(false); } } }); prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE))); prxUseBox.doClick(); proxyChangeState = false; prxHostField.addKeyListener(prxChangeListener); prxUserField.addKeyListener(prxChangeListener); prxPassField.addKeyListener(prxChangeListener); prxPortSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { proxyChangeState = true; } }); prxPanel.add(prxUseBox); prxPanel.add(prxHostLabel); prxPanel.add(prxHostField); prxPanel.add(prxPortLabel); prxPanel.add(prxPortSpinner); prxPanel.add(prxUserLabel); prxPanel.add(prxUserField); prxPanel.add(prxPassLabel); prxPanel.add(prxPassField); prxPanel.add(Box.createVerticalBox()); final JPanel advPanel = new JPanel(); BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS); advPanel.setLayout(advLayout); panes.add("Advanced", advPanel); panes.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JTabbedPane pane = (JTabbedPane) e.getSource(); if (proxyChangeState && pane.getSelectedComponent() == advPanel) { Properties properties = new Properties(); properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim()); properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim()); properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim()); properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString()); properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected())); ProxyCfg prx = ProxyCfg.parseConfig(properties); setProxy(prx); revalidateSearcher(null); } } }); JLabel domainLabel = new JLabel("Deviant Art domain name"); domainLabel.setToolTipText("The deviantART main domain, should it ever change."); domainField = new JTextField(config.getProperty(Constants.DOMAIN)); domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT); domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2)); advPanel.add(domainLabel); advPanel.add(domainField); JLabel throttleLabel = new JLabel("Throttle search delay"); throttleLabel.setToolTipText( "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download."); throttleSpinner = new JSpinner(); throttleSpinner.setModel( new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1)); throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT); throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2)); advPanel.add(throttleLabel); advPanel.add(throttleSpinner); JLabel searcherLabel = new JLabel("Searcher"); searcherLabel.setToolTipText("Select a searcher that will look for your favorites."); searcherBox = new JComboBox(); searcherBox.setRenderer(new TogglingRenderer()); final AtomicInteger index = new AtomicInteger(0); searcherBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox combo = (JComboBox) e.getSource(); Object selectedItem = combo.getSelectedItem(); if (selectedItem instanceof SearchItem) { SearchItem item = (SearchItem) selectedItem; if (item.isValid) { index.set(combo.getSelectedIndex()); } else { combo.setSelectedIndex(index.get()); } } } }); try { for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) { Search searcher = clazz.newInstance(); String name = searcher.getName(); SearchItem item = new SearchItem(name, clazz.getName(), true); searcherBox.addItem(item); } String selectedClazz = config.getProperty(Constants.SEARCHER, com.dragoniade.deviantart.deviation.SearchRss.class.getName()); revalidateSearcher(selectedClazz); } catch (Exception e1) { throw new RuntimeException(e1); } searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT); searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2)); advPanel.add(searcherLabel); advPanel.add(searcherBox); advPanel.add(Box.createVerticalBox()); add(panes, BorderLayout.CENTER); JButton saveBut = new JButton("Save"); userField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; if (field.getText().trim().length() == 0) { JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); locationField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; String content = field.getText().trim(); if (content.length() == 0) { JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } if (!content.contains("%filename%") && !content.contains("%id%")) { JOptionPane.showMessageDialog(input, "The location must contains at least a %filename% or an %id% field.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); locationMatureField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; String content = field.getText().trim(); if (content.length() == 0) { JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } if (!content.contains("%filename%") && !content.contains("%id%")) { JOptionPane.showMessageDialog(input, "The Mature location must contains at least a %username% or an %id% field.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); domainField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; String domain = field.getText().trim(); if (domain.length() == 0) { JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } if (domain.toLowerCase().startsWith("http://")) { JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); locationField.setVerifyInputWhenFocusTarget(true); final JDialog parent = this; saveBut.addActionListener(new ActionListener() { String errorMsg = "The location is invalid or cannot be written to."; public void actionPerformed(ActionEvent e) { String username = userField.getText().trim(); String location = locationField.getText().trim(); String locationMature = locationMatureField.getText().trim(); String domain = domainField.getText().trim(); String throttle = throttleSpinner.getValue().toString(); String searcher = searcherBox.getSelectedItem().toString(); String prxUse = Boolean.toString(prxUseBox.isSelected()); String prxHost = prxHostField.getText().trim(); String prxPort = prxPortSpinner.getValue().toString(); String prxUsername = prxUserField.getText().trim(); String prxPassword = new String(prxPassField.getPassword()).trim(); if (!testPath(location, username)) { JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE); } if (!testPath(locationMature, username)) { JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE); } Properties p = new Properties(); p.setProperty(Constants.USERNAME, username); p.setProperty(Constants.LOCATION, location); p.setProperty(Constants.MATURE, locationMature); p.setProperty(Constants.DOMAIN, domain); p.setProperty(Constants.THROTTLE, throttle); p.setProperty(Constants.SEARCHER, searcher); p.setProperty(Constants.SEARCH, selectedSearch.getId()); p.setProperty(Constants.PROXY_USE, prxUse); p.setProperty(Constants.PROXY_HOST, prxHost); p.setProperty(Constants.PROXY_PORT, prxPort); p.setProperty(Constants.PROXY_USERNAME, prxUsername); p.setProperty(Constants.PROXY_PASSWORD, prxPassword); owner.savePreferences(p); parent.dispose(); } }); JButton cancelBut = new JButton("Cancel"); cancelBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { parent.dispose(); } }); JPanel buttonPanel = new JPanel(); BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS); buttonPanel.setLayout(butLayout); buttonPanel.add(saveBut); buttonPanel.add(cancelBut); add(buttonPanel, BorderLayout.SOUTH); pack(); setResizable(false); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2); setVisible(true); }
From source file:com.diversityarrays.kdxplore.trials.AddScoringSetDialog.java
public AddScoringSetDialog(Window owner, KdxploreDatabase kdxdb, Trial trial, Map<Trait, List<TraitInstance>> instancesByTrait, SampleGroup curatedSampleGroup) { super(owner, Msg.TITLE_ADD_SCORING_SET(), ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.kdxploreDatabase = kdxdb; this.trial = trial; this.curatedSampleGroupId = curatedSampleGroup == null ? 0 : curatedSampleGroup.getSampleGroupId(); Map<Trait, List<TraitInstance>> noCalcs = instancesByTrait.entrySet().stream() .filter(e -> TraitDataType.CALC != e.getKey().getTraitDataType()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Map<Trait, List<TraitInstance>> noCalcsSorted = new TreeMap<>(TRAIT_COMPARATOR); noCalcsSorted.putAll(noCalcs);//from www .j a v a2s .c om BiFunction<Trait, TraitInstance, String> parentNameProvider = new BiFunction<Trait, TraitInstance, String>() { @Override public String apply(Trait t, TraitInstance ti) { if (ti == null) { List<TraitInstance> list = noCalcsSorted.get(t); if (list == null || list.size() != 1) { OptionalInt opt = traitInstanceChoiceTreeModel.getChildChosenCountIfNotAllChosen(t); StringBuilder sb = new StringBuilder(t.getTraitName()); if (opt.isPresent()) { // only some of the children are chosen int childChosenCount = opt.getAsInt(); if (childChosenCount > 0) { sb.append(" (").append(childChosenCount).append(" of ").append(list.size()) .append(")"); } } else { // all of the children are chosen if (list != null) { sb.append(" (").append(list.size()).append(")"); } } return sb.toString(); } } return t.getTraitName(); } }; Optional<List<TraitInstance>> opt = noCalcsSorted.values().stream().filter(list -> list.size() > 1) .findFirst(); String heading1 = opt.isPresent() ? "Trait/Instance" : "Trait"; traitInstanceChoiceTreeModel = new ChoiceTreeTableModel<>(heading1, "Use?", //$NON-NLS-1$ noCalcsSorted, parentNameProvider, childNameProvider); // traitInstanceChoiceTreeModel = new TTChoiceTreeTableModel(instancesByTrait); traitInstanceChoiceTreeModel.addChoiceChangedListener(new ChoiceChangedListener() { @Override public void choiceChanged(Object source, ChoiceNode[] changedNodes) { updateCreateAction("choiceChanged"); treeTable.repaint(); } }); traitInstanceChoiceTreeModel.addTreeModelListener(new TreeModelListener() { @Override public void treeStructureChanged(TreeModelEvent e) { } @Override public void treeNodesRemoved(TreeModelEvent e) { } @Override public void treeNodesInserted(TreeModelEvent e) { } @Override public void treeNodesChanged(TreeModelEvent e) { updateCreateAction("treeNodesChanged"); } }); warningMsg.setText(PLEASE_PROVIDE_A_DESCRIPTION); warningMsg.setForeground(Color.RED); Container cp = getContentPane(); Box sampleButtons = null; if (curatedSampleGroup != null && curatedSampleGroup.getAnyScoredSamples()) { sampleButtons = createWantSampleButtons(curatedSampleGroup); } Box top = Box.createVerticalBox(); if (sampleButtons == null) { top.add(new JLabel(Msg.MSG_THERE_ARE_NO_CURATED_SAMPLES())); } else { top.add(sampleButtons); } top.add(descriptionField); cp.add(top, BorderLayout.NORTH); descriptionField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateCreateAction("documentListener"); } @Override public void insertUpdate(DocumentEvent e) { updateCreateAction("documentListener"); } @Override public void changedUpdate(DocumentEvent e) { updateCreateAction("documentListener"); } }); updateCreateAction("init"); // KDClientUtils.initAction(ImageId.`CHECK_ALL, useAllAction, "Click to Use All"); treeTable = new JXTreeTable(traitInstanceChoiceTreeModel); treeTable.setAutoResizeMode(JXTreeTable.AUTO_RESIZE_ALL_COLUMNS); TableCellRenderer renderer = treeTable.getDefaultRenderer(Integer.class); if (renderer instanceof JLabel) { ((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); } Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(useAllAction)); buttons.add(new JButton(useNoneAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(warningMsg); buttons.add(new JButton(cancelAction)); buttons.add(Box.createHorizontalStrut(10)); buttons.add(new JButton(createAction)); cp.add(new JScrollPane(treeTable), BorderLayout.CENTER); cp.add(buttons, BorderLayout.SOUTH); pack(); }
From source file:metdemo.Finance.SHNetworks.java
/** * // w ww. j ava 2 s . c om * @param jp * @param usersarray * @param viphm_hashmap */ protected void addBottomControls(final JPanel jp, String[] usersarray) { // create the control panel which will hold settings and picked list final JPanel control_panel = new JPanel(); jp.add(control_panel, BorderLayout.SOUTH); control_panel.setLayout(new BorderLayout()); // create the settings panel which will hold all of the settings Box settings_box = Box.createVerticalBox(); settings_box.setBorder(BorderFactory.createTitledBorder("Display Settings")); control_panel.add(settings_box, BorderLayout.NORTH); JPanel settings_panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10)); // add the zoom controls to the settings panel JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // call listener in GraphMouse instead of manipulating vv scale // directly // this is so the crossover from zoom to scale works with the // buttons // as well as with the mouse wheel Dimension d = m_visualizationview.getSize(); m_graphmouse.mouseWheelMoved( new MouseWheelEvent(m_visualizationview, MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, d.width / 2, d.height / 2, 1, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 1)); } }); JButton minus = new JButton(" - "); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // call listener in GraphMouse instead of manipulating vv scale // directly // this is so the crossover from zoom to scale works with the // buttons // as well as with the mouse wheel Dimension d = m_visualizationview.getSize(); m_graphmouse.mouseWheelMoved( new MouseWheelEvent(m_visualizationview, MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, d.width / 2, d.height / 2, 1, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, -1)); } }); Box zoomPanel = Box.createHorizontalBox(); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); minus.setAlignmentX(Component.LEFT_ALIGNMENT); plus.setAlignmentX(Component.RIGHT_ALIGNMENT); zoomPanel.add(minus); zoomPanel.add(plus); settings_panel.add(zoomPanel); // add the mouse mode combo box to the settings panel JComboBox modeBox = m_graphmouse.getModeComboBox(); modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); m_graphmouse.setMode(ModalGraphMouse.Mode.PICKING); JPanel modePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); settings_panel.add(modePanel); // add the display type combo box to the settings panel String[] layoutTypeStrings = { "OrgChart Layout", "FR Layout" }; layoutTypeBox = new JComboBox(layoutTypeStrings); layoutTypeBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (layoutTypeBox.getSelectedIndex() == 0) moveVertices();//viphm_hashmap); else m_visualizationview.restart(); } }); layoutTypeBox.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel displayTypePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; displayTypePanel.setBorder(BorderFactory.createTitledBorder("Display Type")); displayTypePanel.add(layoutTypeBox); settings_panel.add(displayTypePanel); // add user search to the panel - SHLOMO JPanel searchPanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; // take the users and organize it sorted /* * ArrayList<String> ta = new ArrayList<String>(userlist); String [] * usersarray = (String[]) ta.toArray(new String[ta.size()]); */Arrays.sort(usersarray); usercombolist = new JComboBox(usersarray); usercombolist.insertItemAt("Anyone", 0); usercombolist.setSelectedIndex(0);// show only anyone choice // lets add all current users to the list searchPanel.setBorder(BorderFactory.createTitledBorder("Search User")); searchPanel.add(usercombolist); //add a check box to show not show labels on all vertices m_showLabels = new JCheckBox("Show name?", false); settings_panel.add(m_showLabels); settings_panel.add(searchPanel); usercombolist.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // will need to react to the choice list if (usercombolist.getSelectedIndex() == 0) { // might have to reset something in case they move back PickedState picked_state = m_visualizationview.getPickedState(); picked_state.clearPickedVertices(); return; } String username = (String) usercombolist.getSelectedItem(); for (Iterator walker = m_layout.getVertexIterator(); walker.hasNext();) { VIPVertex V = (VIPVertex) walker.next(); // Integer indexNum = (Integer)index.getNumber(V); String seeName = V.getAcct();// accounts_arraylist.get(indexNum); if (username.equals(seeName)) { PickedState picked_state = m_visualizationview.getPickedState(); picked_state.clearPickedVertices(); picked_state.pick(V, true); /* * int x= (int)m_layout.getX(V); int y= * (int)m_layout.getY(V); //lets trigger the event * m_graphmouse.mousePressed(new * MouseEvent(m_visualizationview,MouseEvent.MOUSE_CLICKED,System.currentTimeMillis(),0,x,y,2,false)); */return; } } } }); // add the settings panel to the settings box settings_box.add(settings_panel); // add the vip table to the control panel SortTableModel model = new SortTableModel(); model.addColumn("Account"); model.addColumn("ResponseScore"); model.addColumn("SocialScore"); m_timeTable = new JTable(model); model.addMouseListenerToHeaderInTable(m_timeTable); m_timeTable.setRowSelectionAllowed(true); m_timeTable.setColumnSelectionAllowed(false); m_timeTable.getTableHeader().setReorderingAllowed(false); m_timeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m_timeTable.setDefaultRenderer(model.getColumnClass(1), md5Renderer); tablePane = new JScrollPane(m_timeTable); tablePane.setPreferredSize(new Dimension(300, 150)); control_panel.add(tablePane, BorderLayout.SOUTH); }