List of usage examples for com.jgoodies.forms.util DefaultUnitConverter getInstance
public static DefaultUnitConverter getInstance()
From source file:eu.lp0.cursus.ui.AboutDialog.java
License:Open Source License
private void initialise() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$ DefaultUnitConverter duc = DefaultUnitConverter.getInstance(); FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$ "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$ getContentPane().setLayout(layout);/*from w w w . j a v a2 s . c o m*/ JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$ getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$ getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$ JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$ JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$ txtCopying.setFont(Font.decode(Font.MONOSPACED)); txtCopying.setEditable(false); scrCopying.setViewportView(txtCopying); scrCopying.setPreferredSize( new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying))); Action actClose = new CloseDialogAction(this); JButton btnClose = new JButton(actClose); getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$ getRootPane().setDefaultButton(btnClose); getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName()); getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose); pack(); setMinimumSize(getSize()); setSize(getSize().width, getSize().height * 3 / 2); btnClose.requestFocusInWindow(); }
From source file:eu.lp0.cursus.ui.common.CommonDetailDialog.java
License:Open Source License
private void initialise() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setTitle(title);/* www. j a v a 2 s. c o m*/ DefaultUnitConverter duc = DefaultUnitConverter.getInstance(); Dimension min = new Dimension(duc.dialogUnitXAsPixel(150, this), duc.dialogUnitYAsPixel(75, this)); min.width += getInsets().left + getInsets().right; min.height += getInsets().top + getInsets().bottom; FormLayout layout = new FormLayout( "2dlu, right:max(30dlu;pref), 2dlu, fill:max(0dlu;pref):grow, max(30dlu;pref), 2dlu, max(30dlu;pref), 2dlu", //$NON-NLS-1$ "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu:grow, max(16dlu;pref), 2dlu"); //$NON-NLS-1$ getContentPane().setLayout(layout); JLabel lblName = new JLabel(Messages.getString("entity.name") + ":"); //$NON-NLS-1$ //$NON-NLS-2$ getContentPane().add(lblName, "2, 2"); //$NON-NLS-1$ txtName = new DatabaseTextField(origItem.getName(), Constants.MAX_STRING_LEN); getContentPane().add(txtName, "4, 2, 4, 1"); //$NON-NLS-1$ JLabel lblDesc = new JLabel(Messages.getString("entity.description") + ":"); //$NON-NLS-1$ //$NON-NLS-2$ getContentPane().add(lblDesc, "2, 4"); //$NON-NLS-1$ txtDesc = new DatabaseTextField(origItem.getDescription(), Constants.MAX_STRING_LEN); getContentPane().add(txtDesc, "4, 4, 4, 1"); //$NON-NLS-1$ Action actCancel = new CancelDialogAction(this); JButton btnCancel = new JButton(actCancel); JButton btnSave = new JButton(new SaveDialogAction() { @Override public void actionPerformed(ActionEvent ae) { doSave(); } }); SwingHacks.addButtonsInUIOrder(getContentPane(), Arrays.asList(btnSave, btnCancel), Arrays.asList("5, 6", "7, 6")); //$NON-NLS-1$ //$NON-NLS-2$ getRootPane().setDefaultButton(btnSave); getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CancelDialogAction.class.getName()); getRootPane().getActionMap().put(CancelDialogAction.class.getName(), actCancel); pack(); setMinimumSize(getSize()); setSize(getSize().width * 3 / 2, getSize().height); }
From source file:jgnash.ui.budget.BudgetWizardDialog.java
License:Open Source License
private void initComponents() { okButton = new JButton(rb.getString("Button.Ok")); cancelButton = new JButton(rb.getString("Button.Cancel")); budgetPeriodCombo = new JComboBox<>(); budgetPeriodCombo.setModel(new DefaultComboBoxModel<>(BudgetPeriod.values())); budgetPeriodCombo.setSelectedItem(BudgetPeriod.MONTHLY); budgetNameField = new JTextField(); DefaultUnitConverter unitConverter = DefaultUnitConverter.getInstance(); helpPane = new JEditorPane(); helpPane.setEditable(false);//from w w w. jav a 2 s. c o m helpPane.setEditorKit(new StyledEditorKit()); helpPane.setBackground(getBackground()); helpPane.setText(TextResource.getString("NewBudgetOne.txt")); helpPane.setPreferredSize(new Dimension(unitConverter.dialogUnitXAsPixel(DLU_X, helpPane), unitConverter.dialogUnitYAsPixel(DLU_Y, helpPane))); roundButton = new JCheckBox(rb.getString("Button.RoundToWhole")); okButton.addActionListener(this); cancelButton.addActionListener(this); }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo.java
License:Open Source License
@Override protected void refresh_afterCreate2() throws Exception { super.refresh_afterCreate2(); FormLayout layout = (FormLayout) getObject(); Container container = getContainer().getContainer(); // prepare origins int[] columnOrigins; int[] rowOrigins; {//from w w w .j a v a 2 s . c om com.jgoodies.forms.layout.FormLayout.LayoutInfo layoutInfo = layout.getLayoutInfo(container); columnOrigins = layoutInfo.columnOrigins; rowOrigins = layoutInfo.rowOrigins; } // initialize default sizes in pixels { DefaultUnitConverter converter = DefaultUnitConverter.getInstance(); // m_defaultColumnSize = converter.millimeterAsPixel(DEFAULT_SIZE, container); m_defaultRowSize = converter.millimeterAsPixel(DEFAULT_SIZE, container); m_gapColumnSize = new FormSizeInfo(FormFactory.RELATED_GAP_COLSPEC.getSize(), true).getConstantSize() .getAsPixels(); m_gapRowSize = new FormSizeInfo(FormFactory.RELATED_GAP_ROWSPEC.getSize(), false).getConstantSize() .getAsPixels(); } // set constant size for empty columns/rows { int columnCount = layout.getColumnCount(); int rowCount = layout.getRowCount(); // update columns for (int column = 1; column <= columnCount; column++) { ColumnSpec spec = layout.getColumnSpec(column); if (columnOrigins[column] - columnOrigins[column - 1] == 0) { spec = ColumnSpec.decode(DEFAULT_SIZE + "mm"); layout.setColumnSpec(column, spec); } } // update rows for (int row = 1; row <= rowCount; row++) { RowSpec spec = layout.getRowSpec(row); if (rowOrigins[row] - rowOrigins[row - 1] == 0) { spec = RowSpec.decode(DEFAULT_SIZE + "mm"); layout.setRowSpec(row, spec); } } // may be column/row specs were updated, force layout container.doLayout(); } }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo.java
License:Open Source License
/** * @return the value in pixels for value in given {@link Unit}. *///from w w w. ja va2 s . c o m public static int convertToPixels(double value, Unit unit) { UnitConverter converter = DefaultUnitConverter.getInstance(); // int pixels = 0; if (unit == ConstantSize.PIXEL) { pixels = (int) value; } else if (unit == ConstantSize.POINT) { pixels = converter.pointAsPixel((int) value, m_toolkitComponent); } else if (unit == ConstantSize.DLUX) { pixels = converter.dialogUnitXAsPixel((int) value, m_toolkitComponent); } else if (unit == ConstantSize.DLUY) { pixels = converter.dialogUnitYAsPixel((int) value, m_toolkitComponent); } else if (unit == ConstantSize.MILLIMETER) { pixels = converter.millimeterAsPixel(value, m_toolkitComponent); } else if (unit == ConstantSize.CENTIMETER) { pixels = converter.centimeterAsPixel(value, m_toolkitComponent); } else if (unit == ConstantSize.INCH) { pixels = converter.inchAsPixel(value, m_toolkitComponent); } // return pixels; }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo.java
License:Open Source License
/** * @return the value in {@link Unit} corresponding to the given <code>methodName</code> and value * in pixels.//from w w w . j a v a 2 s.c o m */ private static int convertFromPixelsInt(int pixels, String methodName) throws Exception { UnitConverter converter = DefaultUnitConverter.getInstance(); Method method = UnitConverter.class.getMethod(methodName, new Class[] { int.class, Component.class }); int result = 0; while (true) { Integer newPixelsValue = (Integer) method.invoke(converter, new Object[] { result, m_toolkitComponent }); int newPixels = newPixelsValue.intValue(); if (newPixels > pixels) { return result; } result++; } }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo.java
License:Open Source License
/** * @return the value in {@link Unit} corresponding to the given <code>methodName</code> and value * in pixels.// ww w . j a v a2 s .co m */ private static double convertFromPixelsDouble(int pixels, String methodName) throws Exception { UnitConverter converter = DefaultUnitConverter.getInstance(); Method method = UnitConverter.class.getMethod(methodName, new Class[] { double.class, Component.class }); double result = 0; while (true) { Integer newPixelsValue = (Integer) method.invoke(converter, new Object[] { new Double(result), m_toolkitComponent }); int newPixels = newPixelsValue.intValue(); if (newPixels > pixels) { return (int) (result * 10) / 10.0; } result += 0.05; } }
From source file:org.openthinclient.console.util.SectionTitleBar.java
License:Open Source License
public SectionTitleBar() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); DefaultUnitConverter duc = DefaultUnitConverter.getInstance(); int leftRight = duc.dialogUnitXAsPixel(4, this); int topBottom = duc.dialogUnitYAsPixel(2, this); setBorder(BorderFactory.createEmptyBorder(topBottom, leftRight, topBottom, leftRight)); updateUI();/*from w w w . ja va 2s. c om*/ }
From source file:org.openthinclient.console.util.SectionTitleBar.java
License:Open Source License
protected void paintComponent(Graphics g) { DefaultUnitConverter duc = DefaultUnitConverter.getInstance(); int w = getWidth() - 1; int h = getHeight(); int bevelSize = duc.dialogUnitXAsPixel(6, this); Graphics2D g2 = (Graphics2D) g; GeneralPath clip = new GeneralPath(); clip.moveTo(0, h);// www . j a v a 2 s . co m clip.lineTo(0, bevelSize); clip.curveTo(0, 0, 0, 0, bevelSize, 0); clip.lineTo(w - bevelSize, 0); clip.curveTo(w, 0, w, 0, w, bevelSize); clip.lineTo(w, h); Color fillColor = UIManager.getColor("InternalFrame.activeTitleGradient"); //$NON-NLS-1$ if (null == fillColor) fillColor = UIManager.getColor("InternalFrame.activeTitleBackground"); //$NON-NLS-1$ Object rhAA = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint painter = new GradientPaint(0, h / 2, new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), 128), 0, h, new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), 0)); g2.setPaint(painter); g2.fill(clip); Color lineColor = getBackground().darker(); painter = new GradientPaint(0, h / 2, lineColor, 0f, h, new Color(lineColor.getRed(), lineColor.getGreen(), lineColor.getBlue(), 0)); g2.setPaint(painter); g2.draw(clip); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rhAA); super.paintComponent(g); }